Community Forums › Forums › Archived Forums › Design Tips and Tricks › Unwanted featured image being displayed
- This topic has 13 replies, 5 voices, and was last updated 5 years ago by Jay.
-
AuthorPosts
-
January 4, 2014 at 3:52 pm #83253MatthewParticipant
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?
http://test.goldsbrough.biz//* 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' ) ); } }
January 4, 2014 at 3:59 pm #83255Brad DaltonParticipantJanuary 4, 2014 at 4:04 pm #83258MatthewParticipantBrad, I do want the featured image to be displayed if it is there.
January 4, 2014 at 4:07 pm #83259Brad DaltonParticipantJanuary 4, 2014 at 4:20 pm #83261Brad DaltonParticipantBy 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
add_action( 'genesis_entry_header', 'streamline_post_image', 1 );
If you change the 1 to 11, it will display after the title and before the content
Here's the hook guide.
January 4, 2014 at 6:42 pm #83283MatthewParticipantI'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?
January 6, 2014 at 2:22 am #83551MatthewParticipantAnyone?
January 6, 2014 at 9:55 am #83592SummerMemberAre 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.community/topic/no-need-for-featured-image-in-pro-themes/
WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
Slice of SciFi | Writers, After DarkJanuary 6, 2014 at 4:58 pm #83672MatthewParticipantHi, 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.
January 7, 2014 at 12:10 pm #83847MatthewParticipantOK, 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!!!
January 7, 2014 at 4:22 pm #83888SummerMemberWhat 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.
WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
Slice of SciFi | Writers, After DarkJanuary 7, 2014 at 11:14 pm #83943MatthewParticipantThanks, Summer, that's working nicely.
January 20, 2014 at 7:07 pm #86206caseymMemberHi Summer. Just want to say thank you for posting that solution. I had the exact problem and was able to fix it. 🙂
Casey
August 25, 2019 at 1:18 pm #493168JayMemberThis is now 2019. I was having the same issue.
Thank you Summer.It worked perfectly!
Jay
-
AuthorPosts
- The topic ‘Unwanted featured image being displayed’ is closed to new replies.