• Hello Experts,
    Can some one explain to me a way to add caption right underneath the featured image on posts when the theme doesn’t do it by default? It seems like the theme I’m using doesn’t have option to enable it.. I’m trying to figure this out without using a third-party plugin..
    The theme I’m using has a peculiar effect when the visitor hover on top of post images on the homepage of my website – it dims the image and the first character used in the text on the post appears as an initial. Does anyone know a way to disable this? I’m providing a link to my homepage.
    Would appreciate any advise. Thank you in advance,

    • This topic was modified 6 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    You’re using a commercial theme, so please use their official support channel. We feel they are best equipped to support their products.

    https://pixelgrade.com/support/

    Commercial products are not supported in these forums.

    general answer to part one of your question:

    add the caption to a featured image, try this code in functions.php of your (child) theme:

    // dec 17 2016 @alchymyth
    // filter to show caption, if available, on thumbnail, wrapped with '.wp-caption thumb-caption' div;
    // show just the thumbnail otherwise
     
    add_filter( 'post_thumbnail_html', 'add_post_thumbnail_caption',10,5 );
     
    function add_post_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr) {
     
    if( $html == '' ) { 
      
        return $html;
      
    } else {
      
        $out = '';
      
        $thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment'));
      
        if ($thumbnail_image && isset($thumbnail_image[0])) {
      
            $image = wp_get_attachment_image_src($post_thumbnail_id, $size);
     
            if($thumbnail_image[0]->post_excerpt) 
                $out .= '<div class="wp-caption thumb-caption">';
      
            $out .= $html;
      
            if($thumbnail_image[0]->post_excerpt) 
                $out .= '<p class="wp-caption-text thumb-caption-text">'.$thumbnail_image[0]->post_excerpt.'</p></div>';
       
        }
     
        return $out;
       
    }
    }

    The minor ‘downside’ of this approach is that the caption will be shown with the post thumbnail (featured image) in any location where it is used, which might not always be desired.

    needs CSS to adapt to your theme.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘caption on featured images & disabling hover effect’ is closed to new replies.