WordPress.org

Ready to get started?Download WordPress

Forums

Default featured image
Apply only to one custom post type (13 posts)

  1. myhero
    Member
    Posted 7 months ago #

    Hi,
    How can I apply this to only one, custom post type?
    Thank you

    http://wordpress.org/plugins/default-featured-image/

  2. myhero
    Member
    Posted 7 months ago #

    It's adding images to Ubermenu too, I'd like to limit it to one post type.

  3. janw.oostendorp
    Member
    Plugin Author

    Posted 7 months ago #

    Hi,

    Paste the code below in your functions.php. Change the name of the CUSTOM_POSTTYPE to the posttype you need. Let me know how it goes.

    function dfi_posttype( $dfi_id ) {
    		if ( is_singular( 'CUSTOM_POSTTYPE' ) || get_post_type() == 'CUSTOM_POSTTYPE' ) {
    				return $dfi_id; // The featured image set in the media settings
    		}
    		return; // no featured image
    }
    add_filter('dfi_thumbnail_id', 'dfi_posttype' );
  4. myhero
    Member
    Posted 7 months ago #

    Hi there,
    Thanks for the code. I've applied and have replaced the "CUSTOM_POSTTYPE" text with my custom post type name without success. It is still showing images on my menu. Can I limit it to only the one custom post type?

    Thank you

    My code:

    //Default featured Image
    function dfi_posttype( $dfi_id ) {
    		if ( is_singular( 'jobs' ) || get_post_type() == 'jobs' ) {
    				return $dfi_id; // The featured image set in the media settings
    		}
    		return; // no featured image
    }
    add_filter('dfi_thumbnail_id', 'dfi_posttype' );
  5. janw.oostendorp
    Member
    Plugin Author

    Posted 7 months ago #

    Mhh, what menu are you using? Then I can compare the combination

  6. myhero
    Member
    Posted 7 months ago #

    Thanks, I'm using UberMenu from CodeCanyon

  7. janw.oostendorp
    Member
    Plugin Author

    Posted 6 months ago #

    Hee,

    I've updated the plugin. It has a beter way to filter this. Can you try this code:

    function dfi_posttype_jobs ( $dfi_id, $post_id ) {
      $post = get_post($post_id);
      if ( 'jobs' === $post->post_type ) {
        return $dfi_id; // the image id
      }
      return null; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );
  8. Justin Fletcher
    Member
    Posted 6 months ago #

    Hi Janw.oostendorp,

    Have you thought of extending the plugin to cater for multiple custom post types? so if you had post types like "book" and "podcast" ..etc you could define a different default featured images for each.

    I think that would be a great enhancement.

    ..Justin

  9. janw.oostendorp
    Member
    Plugin Author

    Posted 6 months ago #

    Hi Justin,

    I thought of it but never got around it. Mostly because I want to keep is user-friendly as possible. I kinda like how simple it is.
    If I can think of a way to keep is simple I'll probably add id.
    It's not hard technical.

  10. Justin Fletcher
    Member
    Posted 6 months ago #

    Hi Janw,

    Its a great plugin and provides consistency for posts to never have a missing featured image. To have a checkbox for any post types available when a CPT supports 'thumbnail' would be great.

    so your suggestion of an "id" if that's for a CPT name-id then yes great (for CPTs that support 'thumbnail'). If you were then to add the ability for one or more featured-image/CPT associations then that's another way and wouldn't take more space in the media settings than is needed.

    But anyway its a thought and would add to your great work.

    ..Justin.

  11. colinsp
    Member
    Posted 4 months ago #

    Jan, do you know if this code worked?

    I only want to apply this plugin to one Custom Post Type and so the added functionality / this code in functions.php is important to me.

  12. janw.oostendorp
    Member
    Plugin Author

    Posted 4 months ago #

    @Colinsp
    Did you try the code? It should work.

  13. colinsp
    Member
    Posted 4 months ago #

    Jan,

    I haven't tried it out yet I was hoping that @myhero would report back whether it was working or not or that he had pm'd you with the result of his testing.

    I will give it a try next week and report back.

Reply

You must log in to post.

About this Plugin

About this Topic