0

I'm trying to get the featured image of a post in wordpress and output it as the background image of a div and align it to the bottom right of the div.

So far I have the code shown below but the background-image: url(' . wp_get_attachment_url() . '); is returning as background-image: url(); when the code is executed.

Thanks in advance to anyone that can help!

<?php query_posts(array( 'category_name' => 'what-we-do')); if(have_posts()) : while(have_posts()) : the_post(); ?> <div> <?php echo do_shortcode( ' [expand title="' . get_the_title() . '" swaptitle="Close" trigpos="below" id="' . get_the_ID() . '" trigclass="arrowright" rel="whatwedo-highlander"] <h4 class="collapse-inner-title">' . get_the_title() . '</h4> <div class="whatwedo-collapse-background-img" style="background-image: url(' . wp_get_attachment_url() . '); background-position: right bottom;"> <div class="whatwedo-collapse-content">' . get_the_content() . '</div> </div> [/expand] ' ); ?> </div> <?php endwhile; endif; wp_reset_query(); ?> 

1 Answer 1

2

Try this:

$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );

then us $image[0] When setting the background-image

Sign up to request clarification or add additional context in comments.

1 Comment

You, sir, are a gentleman. Thank you for your quick response and clear instructions. Worked perfectly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.