Support » Plugins » Hacks » get_stylesheet_directory_uri won't work for me

  • I am trying to put an image into my site with an action hook. I was able to get it to work fine using HTML with the image in my media library using this code

    <div class="home-buttons">
    		<img id="home-buttons" src ="

    Then I decided I wanted the image in the images folder of my child theme (which is the active theme on my site). I then changed the code to this

    <div class="home-buttons">
    		<img id="home-buttons" src="<?php echo get_stylesheet_directory_uri() ?>/images/home-buttons.png" />

    but the image won’t load. Instead I get that no image icon (and nothing in firefox)
    The image is definitely in the images folder because I can view it in cPanel and I haven’t given it the wrong name because I just used copy and paste.
    Any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can use the following instead of get_stylesheet_directory_uri function:

    <img id="home-buttons" src="<?php echo get_bloginfo('template_directory'); ?>/images/home-buttons.png" />

    Thanks, I tried it but it didn’t work.
    Also, I though ‘template_directory’ was for parent themes. I’m using a child theme. Does that matter?

    You can use that no problem.

    I must be doing something else wrong then. Thanks for your help, I’ll keep trying.

    Can you share your site url?

    You should use template_directory as the following:

    <img src="<?php bloginfo('template_directory'); ?>/images/mainimage.jpg" title="" alt="" />

    I tried it again but it just doesn’t work. Here is the code, cut & paste, that does work with the image in my media library;

    <div class="menu-buttons-1">
    		<p id="menu-links-1"><img style="...etc" src="" title="Use the search form above to find a music teacher in your area" alt="Find a music teacher"></p>

    And here, cut & pasted again, is the code that I just tried with a random image from my images folder;

    <div class="menu-buttons-1">
    		<p id="menu-links-1"><img src="<?php bloginfo('template_directory'); ?>/images/footer-bg.jpg" title="" alt="" /></p>

    When I tried that I got this message;

    Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/arjuna/public_html/wp-content/themes/vantage-child/functions.php on line 42

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘get_stylesheet_directory_uri won't work for me’ is closed to new replies.