WordPress.org

Support

Support » Themes and Templates » Adding img tag into a template with a relative link

Adding img tag into a template with a relative link

  • 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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    @esmi

    Forum Moderator

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

    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.

    esmi

    @esmi

    Forum Moderator

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

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

    Yep, that worked perfectly! Thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding img tag into a template with a relative link’ is closed to new replies.
Skip to toolbar