Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I use this code:

<?php wp_nav_menu( array( 'theme_location' => 'slider', 'link_before' => '<img src="'.bloginfo( 'template_directory' );.'/images/icon.png" alt="" />' ) );

got following error:

Parse error: syntax error, unexpected T_STRING, expecting ')' in PATH/slideshow.php on line 30 ?>

Whereas following code is running fine:

<?php wp_nav_menu( array( 'theme_location' => 'slider', 'link_before' => '<img src="http://WEBSITE.COM/FULLPATH/images/icon.png" alt="" />' ) ); ?>

But I dont want to use static path. Could someone help me?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You have two problems in your code:

  • the function bloginfo will print the information, and you only need to pass it to the wp_nav_menu function, so the correct function would be get_bloginfo
  • also, in situations like this: echo 'html_code'.php_function().'other_html_code' you don't use the semicolon after the php function

And as a last comment, instead of using get_bloginfo, it is recommended that you use get_stylesheet_directory_uri (this will retrieve the folder of the child theme or the normal folder theme, if no child is being used).

This is the working code:

wp_nav_menu( array( 'theme_location' => 'slider', 'link_before' => '<img src="'.get_stylesheet_directory_uri().'/images/icon.png" alt="" />' ) );
share|improve this answer
Thanks for the correction. –  Kash May 30 '12 at 19:35

If the image is purely decorative and non-essential, you might consider doing this with CSS's :before attribute. Something like:

.menu-item:before {
    display:inline-block; content:''; width:20px; height:20px;
    background: url(images/icon.png) no-repeat;

Otherwise, @brasofilo's answer is right.

UPDATED 9/21/12: Also, icon fonts are all the rage now. If doing that, you'd put the glyph in the content:'' property and nix the background.

share|improve this answer
Thanks for providing another solution. –  Kash May 30 '12 at 19:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.