WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. HappyCloud
    Member
    Posted 3 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. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

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

    Thanks, the first method worked a treat :]

  4. comprido
    Member
    Posted 2 years ago #

    Second method works fine for me.
    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.