Hello Haris,
Create the file: wp-content/plugins/default-featured-image-no-pages.php
Add the following code to that file:
<?php
/**
* Plugin Name: Default Featured Image, exclude pages.
* Plugin URI: https://ww.wp.xz.cn/support/topic/remove-dft-from-pages/
* Description: Handle the basics with this plugin.
* Version: 1.0
*/
function dfi_posttype_page ( $dfi_id, $post_id ) {
$post = get_post($post_id);
if ( 'page' === $post->post_type ) {
return 0; // zero is not DFI
}
return $dfi_id; // the original featured image id
}
add_filter( 'dfi_thumbnail_id', 'dfi_posttype_page', 10, 2 );
Don’t forget the activate the plugin after creating it.
Let me know how it goes!
Jan-Willem
I was looking for something similar, and this worked for me! I have a follow-up question, though: Is there a similarly simple way to exclude the new plugin from the search results page? That is, I want the thumbnails to show up for every result from a search, regardless of the post type.
Hello David,
Yes it’s totally possible to make the exception for the searchpage.
<?php
/**
* Plugin Name: Default Featured Image, exclude pages.
* Plugin URI: https://ww.wp.xz.cn/support/topic/remove-dft-from-pages/
* Description: Handle the basics with this plugin.
* Version: 1.0
*/
function dfi_posttype_page ( $dfi_id, $post_id ) {
if ( is_search() ) {
return $dfi_id; // on search pages always show the DFI
}
$post = get_post($post_id);
if ( 'page' === $post->post_type ) {
return 0; // zero is not DFI
}
return $dfi_id; // the original featured image id
}
add_filter( 'dfi_thumbnail_id', 'dfi_posttype_page', 10, 2 );
Let me know how it goes.
That works perfectly. Thank you! 🙂
Thank you Jan! It worked perfectly on my site.
And I’m glad to see my question helped out others as well.
I’ve tried this but it doesn’t work for me. Is the folder location for the file correct? I have changed permissions to 775 also, still didn’t work.
Thanks for the great plugin!
Hi Shilldiy,
Sorry to hear that, in the example we create a small plugin.
Did you active that plugin? Does it show in the plugin list?
Did you clear the cache, if you have that.
Let me know
Jan-Willem
🤦♂️ I had not picked up on this, was ensuring the original plugin was activated… now works a charm! Thank you Jan hugely. Steve