Support » Plugin: Default featured image » Remove DFT from ‘Pages’

  • Resolved Haris Nadeem

    (@monst3r)


    Hello, can you please help in removing DFT from all the ‘Pages’ from my website? I want it to keep working on all my ‘Posts’.

    I mainly want to remove it from my “About” and “Contact” pages, but it’s okay if it doesn’t show up on any of my other pages either.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author janw.oostendorp

    (@janwoostendorp)

    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://wordpress.org/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

    screenwavedavid

    (@screenwavedavid)

    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.

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    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://wordpress.org/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.

    screenwavedavid

    (@screenwavedavid)

    That works perfectly. Thank you! 🙂

    Thread Starter Haris Nadeem

    (@monst3r)

    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!

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Remove DFT from ‘Pages’’ is closed to new replies.