I have a WP site whose center column is variable width.

I would like the featured image to appear front and center - 100% width. If I hard code the image path using a plain old image tag with width=100% it looks exactly as I want.

For obvious reasons I don't want it hard coded.

I'm currently using this but the image goes outside of the bounds of the column.

<?php echo get_the_post_thumbnail($id, 'full', array('class' => 'aligncenter')); ?>

So, my question is this.

How can I mimic the behavior of <img src="myimage.png" width="100%" /> but with the get_the_post_thumbnail convention.

  • Would have appreciated a comment as to the reason for the downvote. I'm happy to improve the question or fix any glaring omissions.
    – RThomas
    Commented Oct 17, 2012 at 4:11

2 Answers 2


I ended up using the following to solve my problem.

<?php $image_id = get_post_thumbnail_id(); ?>
<?php $image_attributes = wp_get_attachment_image_src( $image_id, 'full');  ?>
<img src="<?php echo $image_attributes[0]; ?>" width="100%">

get_the_post_thumbnail() has multiple filters. Just make use of them from within your functions.php file to catch them all:

$size = apply_filters( 'post_thumbnail_size', $size );
do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );

Else you can still go with my »Dynamic image resize« plugin.

  • 1
    I solved my problem another way. I'm sure it's obvious that I'm new to wordpress... But thanks for your post - it started me on a whole new topic to learn now. Filters. Seems like they could come in handy :)
    – RThomas
    Commented Sep 19, 2012 at 5:19
  • Filters are meant to be used right at that second where you need something that's not straight forward with using the public template API/template tags. Hooks are meant to extend stuff on the fly. So put everything you need always in your templates with template tags, alter your special situations with filters and extend on demand with hooks and conditional tags.
    – kaiser
    Commented Sep 19, 2012 at 9:48

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.