WordPress.org

Ready to get started?Download WordPress

Forums

image URL in css question (3 posts)

  1. Jarvarro
    Member
    Posted 3 years ago #

    I have a few small date and author post images in my theme, the code I'm using to display them in the css is.

    background:url(http://mysite/wp-content/themes/2010-weaver/images/user.png) no-repeat

    I was wondering if there is another url I could be using instead of the full path. background(themedir/images/image.png or something. With some themes I can just use images/image.png but with 2010 weaver that doesn't work.

  2. curlybracket
    Member
    Posted 3 years ago #

    when adding a picture via CSS, the path always has to be either relative to the css file, or absolute.

    Inline styles are not recommended (because of website performance).
    however, an inline style would allow you to use php-functions like so :

    <?php $themedir = get_bloginfo('stylesheet_directory'); ?>
    <style type="text/css">
    body {
        background: url(<?php echo $themedir; ?>/your-image.png no-repeat;)
    }
    </style>

    see also http://codex.wordpress.org/Function_Reference/get_bloginfo

  3. Jarvarro
    Member
    Posted 3 years ago #

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic