Unwanted featured image being displayed

Community Forums Forums Design Tips and Tricks Unwanted featured image being displayed

This topic is: resolved

This topic contains 12 replies, has 4 voices, and was last updated by  caseym 8 months, 1 week ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #83253

    beyonder
    Member
    Post count: 7

    I’m updating my website to use the Streamline Pro child theme. The theme shows the featured image immediately prior to the post content. I expected that if I remove the featured image, it would no longer be displayed, but for some reason it is. In some way the featured image, which I have removed in the post editor, is still associated with the post.

    I guess this is the section of code in the functions.php that I will need to amend somehow. Can anyone explain what’s going on?

    //* Remove default post image
    remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
    
    //* Add post image above post title
    add_action( 'genesis_entry_header', 'streamline_post_image', 1 );
    function streamline_post_image() {
    
    	if ( is_page() || ! genesis_get_option( 'content_archive_thumbnail' ) )
    		return;
    	
    	if ( $image = genesis_get_image( array( 'format' => 'url', 'size' => genesis_get_option( 'image_size' ) ) ) ) {
    		printf( '<a href="%s" rel="bookmark"><img class="post-photo" src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
    	}
    	
    }
    
    http://test.goldsbrough.biz
    #83255

    braddalton
    Participant
    Post count: 9940
    #83258

    beyonder
    Member
    Post count: 7

    Brad, I do want the featured image to be displayed if it is there.

    #83259

    braddalton
    Participant
    Post count: 9940
    #83261

    braddalton
    Participant
    Post count: 9940

    By default, it displays before the entry meta which is before the title.

    You can reposition the image simply by changing the hook and/or 3rd parameter which is 1
    [php]
    add_action( ‘genesis_entry_header’, ‘streamline_post_image’, 1 );
    [/php]
    If you change the 1 to 11, it will display after the title and before the content

    Here’s the hook guide.


    #83283

    beyonder
    Member
    Post count: 7

    I’ll try to make my question clearer. I’m not wanting to reposition the featured image.

    • I have a post with a featured image.
    • The featured image is shown with the post.
    • I remove the featured image.
    • The featured image is still shown with the post.

    My question is, why is the featured image still displayed when it is no longer associated with the post?

    #83551

    beyonder
    Member
    Post count: 7

    Anyone?

    #83592

    Summer
    Participant
    Post count: 1105

    Are you using the Featured Image meta box in the edit panel, or did you embed an image in the body of the post?

    There’s a behavioral quirk in Genesis where it will take the first post image and make it the featured image by default if you do not specify one, whether you want it to or not.

    Gary Jones said that as of Genesis 2.0, there’s a hook to turn this behavior off. He wrote a filter snippet to do that, and he also helped me write a plugin to shut this behavior off as well.

    See long discussion here: http://www.studiopress.com/forums/topic/no-need-for-featured-image-in-pro-themes/


    #83672

    beyonder
    Member
    Post count: 7

    Hi, Summer,

    Thanks for pointing me in the direction of that thread. It discusses exactly the problem I’m having.

    My first attempt to use the code snippet from GitHub didn’t work properly. I’ll take another look tomorrow.

    #83847

    beyonder
    Member
    Post count: 7

    OK, I’m stumped and could do with some more help…

    To recap…

    • - I’m using the Streamline Pro theme.
    • - If I’ve attached a featured image, I want it to be shown at the top of the post.
    • - If I haven’t attached a featured image, I don’t want an image to be shown there (and I especially don’t want a random image from within the post to be treated as if it’s a ‘featured image’.

    The theme uses this code to show an image for the post.

    
    //* Remove default post image
    remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
    
    //* Add post image above post title
    add_action( 'genesis_entry_header', 'streamline_post_image', 1 );
    function streamline_post_image() {
    
    	if ( is_page() || ! genesis_get_option( 'content_archive_thumbnail' ) )
    		return;
    	
    	if ( $image = genesis_get_image( array( 'format' => 'url', 'size' => genesis_get_option( 'image_size' ) ) ) ) {
    		printf( '<a href="%s" rel="bookmark"><img class="post-photo" src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
    	}
    	
    }
    

    I’ve taken the code by Gary Jones…

    
    add_filter( 'genesis_get_image', 'prefix_stop_auto_featured_image' );
    /**
     * Stop Genesis archives from using first attached image as fallback when no featured image is set.
     *
     * @param  array $args Default image arguments.
     *
     * @return array       Amended default image arguments.
     */
    function prefix_stop_auto_featured_image( $args ) {
    	if ( ! isset( $args['context'] ) || 'archive' !== $args['context'] )
    		return $args;
    	$args['fallback'] = false;
    	return $args;
    }
    

    … and placed it in the functions.php file before the code that came with the theme. That didn’t work, so I modified Gary’s code in several ways, none of which worked.

    I’m exhausted! Help!!!

    #83888

    Summer
    Participant
    Post count: 1105

    What I did in the plugin that Gary helped me write was modify the above code so that it always eliminated the fallback image:

    //* Disable Fallback functionality
    add_filter( 'genesis_get_image_default_args', 'prefix_stop_auto_featured_image' );
    function prefix_stop_auto_featured_image( $args ) {
    	$args['fallback'] = false;
    	return $args;
    }

    Try adding it after the code that moves the image location, and without the conditional. It’s worked beautifully on several test sites I’ve played with it on.

    One caveat, this only works with Genesis 2.0 and above. It will not work with 1.9.2 or earlier because the hook/filter wasn’t there.


    #83943

    beyonder
    Member
    Post count: 7

    Thanks, Summer, that’s working nicely.

    #86206

    caseym
    Member
    Post count: 1

    Hi Summer. Just want to say thank you for posting that solution. I had the exact problem and was able to fix it. :)

    Casey

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.