WordPress.org

Ready to get started?Download WordPress

Forums

get_stylesheet_directory_uri won't work for me (8 posts)

  1. Shunarjuna
    Member
    Posted 1 year ago #

    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 ="http://www.mywebsite.com.au/wp-content/uploads/2012/08/home-buttons.png
    		</div>

    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" />
    		</div>

    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?

  2. Chandan Kumar
    Member
    Posted 1 year ago #

    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" />
  3. Shunarjuna
    Member
    Posted 1 year ago #

    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?

  4. Chandan Kumar
    Member
    Posted 1 year ago #

    You can use that no problem.

  5. Shunarjuna
    Member
    Posted 1 year ago #

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

  6. Chandan Kumar
    Member
    Posted 1 year ago #

    Can you share your site url?

  7. Chandan Kumar
    Member
    Posted 1 year ago #

    You should use template_directory as the following:

    <img src="<?php bloginfo('template_directory'); ?>/images/mainimage.jpg" title="" alt="" />
  8. Shunarjuna
    Member
    Posted 1 year ago #

    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="http://www.teachmemusic.com.au/wp-content/uploads/2012/09/find-a-teacher.png" title="Use the search form above to find a music teacher in your area" alt="Find a music teacher"></p>
    		</div>

    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>
    		</div>

    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

Topic Closed

This topic has been closed to new replies.

About this Topic