I have this snippet of code in my single.php template. It get’s the url of the featured image so I can use it as a background image as apposed to using get_post_thumbnail() which outputs the complete image tag.
if ( has_post_thumbnail() ) {
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
}
Here is where things get strange.
If I var_dump the result I get one output and when I echo I get another.
if ( has_post_thumbnail() ) {
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
$heroimage = $featured_image[0];
echo ($heroimage); // outputs /wp-content/uploads/2016/02/img-social-tweet-dec11.png
var_dump($heroimage); // outputs string(54) "http://assets.d2l.com/wp-content/uploads/2016/02/img-social-tweet-dec11.png"
echo ($heroimage); // outputs http://assets.d2l.com/wp-content/uploads/2016/02/img-social-tweet-dec11.png
echo ($heroimage); // outputs /wp-content/uploads/2016/02/img-social-tweet-dec11.png
}
The echo that immediately follows the var dump is what I am expecting. The others are stripping out the domain name.