Support » Fixing WordPress » Featured image, add image class

  • Resolved HappyCloud


    Im having a bit of trouble, I followed this walkthrough 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)
  • Michael


    Forum Moderator

    you could try to use the $attr of the the_post_thumbnail() function:

    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:

    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.

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