WordPress.org

Forums

[resolved] Stuck using absolute urls (3 posts)

  1. MAK
    Member
    Posted 9 years ago #

    Greetings,

    In my sidebar I use a few small images for the meta links. Why does it seem I am stuck having to use absolute link addresses for the image itself?

    For example - this works:
    <img src="<?php bloginfo('template_directory'); ?>/images/xfn-btn.gif" alt="XFN Friendly" height="15" width="80" />

    but this relative address does not work:
    <img src="/images/xfn-btn.gif" alt="XFN Friendly" height="15" width="80" />

    Like most themes out there all my theme files are located in the root folder for the theme and all my images are in the "images" folder within it.

    I know how relative links work and all about using ../etc etc or ./etc etc when necessary but again, nothing I try works unless I use an absolute/full address.

    Just curious, thanks.

    PS: I am using the date and name permalink structure if that makes any difference.

  2. Kafkaesqui

    Posted 9 years ago #

    You do understand that a url of /images/xfn-btn.gif would start at the root directory of your web site; the first slash / tells a browser "begin looking for images/xfn-btn.gif at the top of the current address."

    So if xfn-btn.gif was located here:

    my.site/blog/wp-content/themes/my-theme/images/xfn-btn.gif

    Your 'relative' src path would fail because the browser is looking here:

    my.site/images/xfn-btn.gif

  3. MAK
    Member
    Posted 9 years ago #

    Yeah you got me there rofl. I forgot about that. In my mind I was thinking everything worked from the theme folder where the files were located.

    Thanks for the friendly reminder.

Topic Closed

This topic has been closed to new replies.

About this Topic