Ok I didn't find an answer yet.. because my code is different.. I want to set the featured image as the div's background but I don't know how to do that.. html, php and css collide in one line.. This is the div..

echo '<div id = "circ"><ul><li><a href = "';
the_permalink(); echo '">'; '</a></li></ul></div>'; ?>

and this is the code I want..

 $src = wp_get_attachment_image_src ( get_post_thumbnail_id('thumbnail'));

<div id = "circ" style="background: url(<?php echo $src[0]; ?> ) !important;">test</div>

I could have inserted it in one line like this

echo '<div id = "circ" style="background: url(<?php echo $src[0];><ul><li><a href = "';
the_permalink(); echo '">'; '</a></li></ul></div>'; 

but then they all collide which I don't know the workaround for it..

  • What do you mean by "collide in one line"? Also, this is looking like a pure PHP problem to me.
    – s_ha_dum
    Jan 18, 2014 at 15:42
  • 1
    for the function get_post_thumbnail_id, the argument should be post_id (interger), but you have given size attribute thumbnail. you can completely remove 'thumbnail' from the function, it should work then
    – Shazzad
    Jan 18, 2014 at 16:18

1 Answer 1


You're code is not working as you have an echo within an echo, try this code (not tested)

echo '<div id = "circ" style="background: url('.$src[0].'><ul><li><a href = "'.the_permalink().'</a></li></ul></div>';

If you're echo'ing something and then you want to add php within that echo you need to break the echo by adding '. $variable .'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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