WordPress.org

Ready to get started?Download WordPress

Forums

Adding img tag into a template with a relative link (5 posts)

  1. dackery_trane
    Member
    Posted 5 years ago #

    Hi All,

    I'm trying to insert an image from my images folder into a custom templates php file. For some reason, if I use a relative link to my images folder, it doesn't work:
    <img src="images/banner_temp.jpg" />

    But if I use an absolute link to my image, it works:
    <img src="http://www.fake.com/images/banner_temp.jpg" />

    Does anyone know how to make an relative uri work in a templates file?

    Thanks in advance... D.T.

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    <img src="<?php bloginfo('url');?>/images/banner_temp.jpg" />

  3. dackery_trane
    Member
    Posted 5 years ago #

    Hi esmi,

    I tried what you suggested but it didn't work. (Maybe it's because I'm running wordpress locally offline.)

    I changed it to this...
    <img src="<?php bloginfo('url');?>/wp-content/themes/theme-name/images/banner_temp.jpg" />

    ...and it worked.

    Thanks esmi for pointing me in the right direction!

    D.T.

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    If the image is within your theme's folders, use:

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

  5. dackery_trane
    Member
    Posted 5 years ago #

    Yep, that worked perfectly! Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic