• Resolved the_briny

    (@the_briny)


    Hi again. Using an Apex child theme, I noticed with today’s update that the featured images – if narrower than 882px – no longer automatically stretch to fill the featured image div. Was this intentional? I liked this functionality and I’d like to insert it back into my child theme. What would you say is the best way to go about this (I’m thinking regenerating thumbnails wouldn’t work on those featured images, since their particular crop/size isn’t defined in the media settings, but I’m not sure if that makes any sense)? Any feedback would be much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter the_briny

    (@the_briny)

    Wanted to update with my fix. It took me a while, but I tracked down the source of my unwanted change to the functions file (not the stylesheets as I had imagined). So I copy and pasted the code pertaining to featured images from the previous update’s functions file into my child theme. Here’s what that bit looks like, for the curious:

    // for displaying featured images
    	if( ! function_exists( 'ct_apex_featured_image' ) ) {
    	        function ct_apex_featured_image() {
    
    	                // get post object
    	                global $post;
    
    	                // default to no featured image
    	                $has_image = false;
    
    	                // establish featured image var
    	                $featured_image = '';
    
    	                // if post has an image
    	                if ( has_post_thumbnail( $post->ID ) ) {
    
    	                        // get the featured image ID
    	                        $image_id = get_post_thumbnail_id( $post->ID );
    
    	                        // get the image's alt text
    	                        $image_alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
    
    	                        // get the full-size version of the image
    	                        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
    
    	                        // set $image = the url
    	                        $image     = $image[0];
    
    	                        // if alt text is empty, nothing else equal to title string
    	                        $title = empty($image_alt_text) ? '' : "title='" . esc_attr( $image_alt_text ) . "'";
    
    	                        // set to true
    	                        $has_image = true;
    	                }
    	                if ( $has_image == true ) {
    
    	                        // on posts/pages display the featured image
    	                        if ( is_singular() ) {
    	                                $featured_image = "<div class='featured-image' style=\"background-image: url('" . esc_url( $image ) . "')\" $title></div>";
    	                        } // on blog/archives display with a link
    	                        else {
    	                                $featured_image = "
    	                <div class='featured-image' style=\"background-image: url('" . esc_url( $image ) . "')\" $title>
    	                    <a href='" . get_permalink() . "'>" . get_the_title() . "</a>
    	                </div>
    	                ";
    	                        }
    	                }
    
    	                // allow videos to be added
    	                $featured_image = apply_filters( 'ct_apex_featured_image', $featured_image );
    
    	                if( $featured_image ) {
    	                        echo $featured_image;
    	                }
    	        }
    	}
    Theme Author Ben Sibley

    (@bensibley)

    Sorry for the change in styling.

    I updated the way images are included to improve compatibility with plugins that utilize featured images (like Pinterest plugins for instance), and this is a bit of a growing pain.

    If you want to limit the width of the featured images to 882px, you can do so by adding the following CSS to your child theme:

    .featured-image > img,
    .featured-image > a > img {
      max-width: 882px
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Featured images no longer stretch to fit content width’ is closed to new replies.