Question on proper syntax for using bloginfo()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
knockeddown
Forum Newbie
Posts: 3
Joined: Sat May 09, 2009 9:59 am

Question on proper syntax for using bloginfo()

Post by knockeddown »

Hi, I'm using wordpress and placing an image on a page with:

Code: Select all

echo "<img src=\"http://www.SITENAME.com/wp-content/them ... GENAME.jpg\" alt=\"IMAGEDESCRIPTION\" />\n";
This works great, but I would really like to use the bloginfo() function so I don't have to type out the entire URL - but I can't figure it out. I'm trying to do something like this:

Code: Select all

echo "<img src=\"bloginfo('template_directory')/images/IMAGENAME.jpg\" alt=\"IMAGEDESCRIPTION\" />\n";
I think I'm screwing up the single and double quotes somehow. Any help on proper syntax is appreciated!
Last edited by Benjamin on Sat May 09, 2009 11:03 am, edited 1 time in total.
Reason: Changed code type from text to php.
Defiline
Forum Commoner
Posts: 59
Joined: Tue May 05, 2009 5:34 pm

Re: Question on proper syntax for using bloginfo()

Post by Defiline »

Code: Select all

<?php
    
    // ...
    echo '<img src="'.bloginfo('template_directory').'/images/IMAGENAME.jpg" alt="IMAGEDESCRIPTION" />';
    // ...
?>
knockeddown
Forum Newbie
Posts: 3
Joined: Sat May 09, 2009 9:59 am

Re: Question on proper syntax for using bloginfo()

Post by knockeddown »

Hey thanks, but it doesn't quite yet work and when I check the source page it looks like this -

Code: Select all

http://www.SITENAME.com/wp-content/themes/THEMENAME/<img src="images/IMAGENAME.jpg" alt="IMAGEDESCRIPTION" />
It is strangely starting the img tag in between the file. Any thoughts? or I could just stick with my original full path name I guess.
knockeddown
Forum Newbie
Posts: 3
Joined: Sat May 09, 2009 9:59 am

Re: Question on proper syntax for using bloginfo()

Post by knockeddown »

Ok, got it working. My mistake - need to use get_bloginfo() here. So we end up with:

Code: Select all

echo '<img src="'.get_bloginfo('template_directory').'/images/IMAGENAME.jpg" alt="IMAGEDESCRIPTION" />';
Thanks again for the help.
Post Reply