[resolved] Featured image, add image class (4 posts)

  1. HappyCloud
    Posted 5 years ago #

    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

  2. Michael
    Part-Time Forum Moderator
    Posted 5 years ago #

    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;
  3. HappyCloud
    Posted 5 years ago #

    Thanks, the first method worked a treat :]

  4. comprido
    Posted 4 years ago #

    Second method works fine for me.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.