Support » Fixing WordPress » Featured image, add image class

  • Resolved HappyCloud

    (@happycloud)


    Im having a bit of trouble, I followed this walkthrough http://www.blog.web6.org/wordpress-3-0-set-featured-image/ to add a featured image to both my index and single pages.

    For the single page however I need to apply an image class so I can use an image zoomer plugin, how can I specify this class with the PHP output of <?php the_post_thumbnail( 'single-post-thumbnail' ); ?>?

    Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • you could try to use the $attr of the the_post_thumbnail() function:
    http://codex.wordpress.org/Function_Reference/the_post_thumbnail

    for instance:

    <?php the_post_thumbnail('post-thumbnail', array( 'class'	=> "zoomer-class attachment-post-thumbnail")); ?>

    where you replace ‘zoomer-class’ with the class required by your plugin.

    if that does not work (it should, tested in local install), you could try and add following filter function to functions.php of your theme:

    add_filter('post_thumbnail_html','add_class_to_thumbnail');
    function add_class_to_thumbnail($thumb) {
    if( is_single() ) $thumb = str_replace('attachment-', 'zoomer-class attachment-', $thumb);
    return $thumb;
    }

    Thanks, the first method worked a treat :]

    Second method works fine for me.
    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Featured image, add image class’ is closed to new replies.