• Resolved Nischal Tiwari

    (@nischaltiwari)


    Hi Dev,

    I am looking for a solution to define a featured image for one particular custom post type only. Is there a way to tweak this plugin, I want to ignore the default Post and Pages.

    Thank you,
    Nischal

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    Hello Nischal,

    Yes it’s possible.
    As noted in the FAQ

    Create a file named wp-content/plugins/dif-no-page-post.php
    Put the following code inside, and activate the plugin in the dashboard

    
    <?php
    
    /**
     * Plugin Name:       Default Featured Image, apply to posts only.
     * Plugin URI:        https://wordpress.org/support/topic/create-default-featured-image-for-one-custom-post-type-only/
     * Version:           1.0
     */
    
    function dfi_no_page_post( $dfi_id, $post_id ) {
    	$post = get_post( $post_id );
    	if ( in_array($post->post_type, array( 'post', 'page',)) ) {
    		return 0; // Don't use DFI for this post or pages
    	}
    
    	return $dfi_id; // the original featured image id
    }0
    
    add_filter( 'dfi_thumbnail_id', 'dfi_no_page_post', 10, 2 );
    

    This should exclude normal posts and pages, to include more posttypes add them in the array in_array($post->post_type, array( 'post', 'page', 'EXTRA',)

    Let me know how it goes.

    Jan-Willem

    Thread Starter Nischal Tiwari

    (@nischaltiwari)

    Hi Jan,

    thank you for the quick response and thanks for providing the code as well. So from the code, what I understood it the plugin works for all and we just need to put exclusions only. Is that correct? It will exclude post, page and any extra cpt etc.

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hello Nischal,

    Yes the code is structured that is will exclude certain posttypes, these will not use the DFI.
    In my example posts and pages are excluded.

    Let me know
    Jan-Willem

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Create default featured image for one custom post type only’ is closed to new replies.