Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 Oct 17 '12 at 4:11
add comment

2 Answers

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.

share|improve this answer
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 Sep 19 '12 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 Sep 19 '12 at 9:48
add comment
up vote 0 down vote accepted

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%">
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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