• Resolved Creativemind18

    (@jobsgivers)


    Thanks for your wonderful plugin and your regular support.

    I already have an existing default image for all post types. But I want to now create a different default image for a specific post type while still maintaining the existing default image for other post types.

    Is there a way to modify your plugin to achieve this.

    I will appreciate your help.

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

    (@janwoostendorp)

    Hello,

    Yes it’s possible.
    As noted in the FAQ

    Create a file named wp-content/plugins/dfi-posttypes.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://ww.wp.xz.cn/support/topic/use-different-default-image-for-different-post-types/
     * Version:     1.0
     */
    
    function dfi_custom_posttypes( $dfi_id, $post_id ) {
    	$post = get_post( $post_id );
    
    	// Set a different image for the post type book.
    	if ( $post->post_type === 'book' ) {
    		return 111; // The image ID.
    	}
    	// Set a different image for the post type book.
    	if ( $post->post_type === 'store' ) {
    		return 222; // The image ID.
    	}
    
    	return $dfi_id; // the original featured image id
    }
    
    add_filter( 'dfi_thumbnail_id', 'dfi_custom_posttypes', 10, 2 );

    You can add more posttypes if you want. Here is a guide to find the image ID.

    Let me know how it goes.

    Jan-Willem

    Thread Starter Creativemind18

    (@jobsgivers)

    This worked well, thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Use different default image for different post types’ is closed to new replies.