Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

On my new worpress install, I have code that reads

<img src="<?php get_stylesheet_directory_uri(); ?>/images/logo.jpg" />

This code worked, untill I started using a subdomain (went from example.com/dev to dev.example.com) and changed these urls in my general settings.

Now the get_stylesheet_directory_uri() does not output anything:

<img src="/images/logo.jpg" />

I swapped it with the following: bloginfo(stylesheet_directory) which seems to work fine, but I am used to get_stylesheet_directory_uri() and it seems like this is the reccomended approach.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

That would be because get_stylesheet_directory_uri only returns a value. If you want to echo it to to the screen you have to include echo or print.

<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/logo.jpg" />

bloginfo works fine as well, but when you do stylesheet_directory it's just a wrapper for get_stylesheet_directory_uri

<?php
function get_bloginfo( $show = '', $filter = 'raw' ) {

    switch( $show ) {
        // snip snip

        case 'stylesheet_directory':
            $output = get_stylesheet_directory_uri();
            break;
        // snip snip
    }
    $url = true;
    if (strpos($show, 'url') === false &&
        strpos($show, 'directory') === false &&
        strpos($show, 'home') === false)
        $url = false;

    if ( 'display' == $filter ) {
        if ( $url )
            $output = apply_filters('bloginfo_url', $output, $show);
        else
            $output = apply_filters('bloginfo', $output, $show);
    }

    return $output;
}
share|improve this answer
1  
well i'll be. I thought I stopped making that mistake a long time ago ;-). Weird though, I could swear it worked for a time before that domain switch –  Zach L Dec 2 '11 at 19:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.