0

The following code is inside a .php file and works; however, I do not know how I can replace the TEXT with a bloginfo('template_directory') to an internal image file. I've search the forums but I cannot find a way to get this to work. Is there an easier way?

if ( $colors && in_array('green', $colors) ) {
    echo '<div class="asdsf">' . "TEXT" . '</div>';
}
1

I assume you're wanting an image tag in there too:

if ( $colors && in_array( 'green', $colors ) ) {
    echo '<div class="asdsf"><img src="';
    echo bloginfo('template_directory') . '/path/within/theme/to/img.png';
    echo '"></div>';
}

But it's better to use the newer get_stylesheet_directory_uri() which will work whether or not you are using a child theme.

if ( $colors && in_array( 'green', $colors ) ) {
    echo '<div class="asdsf"><img src="';
    echo get_stylesheet_directory_uri() . '/path/within/theme/to/img.png';
    echo '"></div>';
}
  • Answer acceptance and votes are thanks enough! :-) As long as it works, anyway! – Andy Macaulay-Brook Oct 14 '16 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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