I’m attempting to use the ‘feature image’ feature of WordPress to make a full screen background, that resizes to fit the browser window using jQuery

The bit I’m stuck on is adding a custom id (#bgimg) to the code generated by this:

<div class="background"><?php the_post_thumbnail (array(1024,768));?></div>

The image generated needs to have specific id tag in it, eg…

<img id="bgimg" src="https://wordpress.stackexchange.com/questions/5454/wordpress/generated/etc.jpg">

So that the jQuery plugin, can hook on to it, and scale it to fit the browser window. I know the jQuery works (as I’ve used it in other projects)

Any suggestions?
Alex

1 Answer
1

Use get_the_post_thumbnail() instead. It allows you to pass in an array of attributes for the image tag that gets returned.

For example:

$attr = array(
    'id' => 'YOUR-UNIQUE-ID',
);

echo get_the_post_thumbnail( $id, 'thumbnail', $attr );

EDIT:

I’m dumb. the_post_thumbnail() also lets you do that. Try passing the same args array I outlined as the second param.

Leave a Reply

Your email address will not be published. Required fields are marked *