Jump to content
Sign in to follow this  
mboehler3

Display an image

Recommended Posts

Hi, I am very very new to PHP and I am trying to build my own Wordpress template from HTML code. I've created the header.php and I'm trying to display an image I have inside my images folder. I believe I need to use an echo statement, but I may be wrong. Can someone please offer me some help? I appreciate it very much, thank you in advance.

Share this post


Link to post
Share on other sites

Nothing special about displaying an image, just use the simple img html tag..if you want to echo it out using php then:<?phpecho "<img src='prettypicture.jpg' alt='' />";?>

Share this post


Link to post
Share on other sites
Nothing special about displaying an image, just use the simple img html tag..if you want to echo it out using php then:<?phpecho "<img src='prettypicture.jpg' alt='' />";?>
Weird, I tried using this code:
<?php echo "<img src='images/get-started.jpg' alt='Get Started' />"; ?>

and the image failed to display. Is there something else I can use?

Share this post


Link to post
Share on other sites

Path names can be tricky in Wordpress. Where exactly is your images directory with respect to your wordpress directory?What your path is telling the browser currently is that 'images' is a directory at the same level as 'index.php' -- if in fact it is above your wordpress directory, or if it is in 'wp-includes' or one of your theme directories (etc.), the browser will be looking in the wrong place.The situation is more complicated if you are using URL-rewriting in an .htaccess file.

Edited by Deirdre's Dad

Share this post


Link to post
Share on other sites
Path names can be tricky in Wordpress. Where exactly is your images directory with respect to your wordpress directory?What your path is telling the browser currently is that 'images' is a directory at the same level as 'index.php' -- if in fact it is above your wordpress directory, or if it is in 'wp-includes' or one of your theme directories (etc.), the browser will be looking in the wrong place.The situation is more complicated if you are using URL-rewriting in an .htaccess file.
I have my images folder inside of my current theme's folder. It still thinks the images directory is at the same level as index.php, even though the path has "images/" in front of it? Since the images folder is in the theme folder (wp-content/themes/[theme name]), how do I tell Wordpress that?Thanks in advance for your help.

Share this post


Link to post
Share on other sites

wp-content/themes/[theme name]/images/get-started.jpgIf that's where it is, that's how to find it.You could of course create an images directory at the same level as your index file. It would change your organizational plan, but it's doable.

Share this post


Link to post
Share on other sites
wp-content/themes/[theme name]/images/get-started.jpgIf that's where it is, that's how to find it.You could of course create an images directory at the same level as your index file. It would change your organizational plan, but it's doable.
Thanks for your help, when I have this code in my header:
<?php echo "<img src='wp-content/themes/warehouse/images/get-started.jpg' alt='Get Started' />"; ?>

the image shows on my homepage (localhost/wordpress/)... however when I go to another page, localhost/wordpress/page/ for example, the image does not display, but the ALT tag does show. Do you know why this is?

Share this post


Link to post
Share on other sites

It's a relative link to the image, so that link will only work for pages in a certain directory. If you want it to work for any page you need to make it an absolute link instead of a relative link.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...