Archived topic
Hide featured image under some conditions
9 replies · Started by webintas on December 2, 2020
Hi there,
In some specific cases I want to remove the featured image. I have tried the code below but that does not work. How to do it?
add_action( 'wp','generate_remove_featured image' );
function generate_remove_featured () {
if (is_single(1256)){
remove_action('generate_before_content','generate_featured_page_header_inside_single', 10);
}
}
Hi there,
In some specific cases I want to remove the featured image.
Can you let me know what those cases are?
It depend on whether a custom field is filled out the the backend. I offer the bloggers an opportunity to insert a YouTube video instead of the featured image. If they do, I need to remove the featured image from single.
Would the disable element metabox help?
https://docs.generatepress.com/article/disable-elements-overview/
You can also create a layout element for it:
https://docs.generatepress.com/article/layout-element-overview/#disable-element
We are on the right track with the disable elements option. But is it possible to do it from the PHP code?
Your function names need to match:
https://www.screencast.com/t/9DsxqVtUvw9Z
And the syntax for is_single need to be corrected as well:
https://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page
Wauw.. How could I miss that.
However, it did not help. I have tried to clean up and keep it simple:
add_action('wp','generate_remove_featured');
function generate_remove_featured () {
remove_action('generate_before_content','generate_featured_page_header_inside_single', 10);
}
That does not work either.
Is the Blog module activated?
If so try this filter instead:
https://docs.generatepress.com/article/option_generate_blog_settings/#options-%E2%80%98single_post_image%E2%80%99
Example:
add_filter( 'option_generate_blog_settings', function( $options ) {
if ( is_single( '17' ) ) {
$options['single_post_image'] = false;
}
return $options;
} );
Thanks ! That helped :-)
No problem :)