WordPress.org

Ready to get started?Download WordPress

Forums

Image path for themes (4 posts)

  1. partridj
    Member
    Posted 8 years ago #

    I'm creating my first theme, however the paths within the theme don't seem to be relative. For instance, if I reference an image file as 'images/header.jpg' it looks in the wordpress/images directory as opposed to wordpress/wp-content/themes/mytheme/images.

    Is there a place to designate the the location of the theme so it will automatically look there for relative paths?

  2. Copernicus
    Member
    Posted 8 years ago #

    I am new at this as well, so take my advice with a grain of salt. But, in my tinkering with themes, I have experienced your same issue & have found that the following is a solution:

    replace something like:
    <img src="images/header.jpg" width="300" height="25" alt="">

    with this:
    <img src="<?php bloginfo('stylesheet_directory'); ?>/images/header.jpg" width="300" height="25" alt="">

  3. partridj
    Member
    Posted 8 years ago #

    Thanks, that works and it looks like that is how it is done in the default template. So unless I figure something else out I will assume that is how it is supposed to work.

  4. katie1
    Member
    Posted 8 years ago #

    I just whack all my images in my wp-images folder and call them using relative URL in my style.css

    (/wp-images/header.jpg)

    If I have lots and lots of themey images, I use folders, too.

    -wp-images
    --zoolander
    ---image.jpg
    --mytheme
    ---image.jp
    --howaboutthat
    ---image.jpg

    (wp-images/zoolander/image.jpg)
    (wp-images/mytheme/image.jpg)
    (wp-images/howaboutthat/image.jpg)

    works for me.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags