Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter myhero

    (@myhero)

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

    Plugin Author Jan-Willem

    (@janwoostendorp)

    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' );
    Thread Starter myhero

    (@myhero)

    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' );
    Plugin Author Jan-Willem

    (@janwoostendorp)

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

    Thread Starter myhero

    (@myhero)

    Thanks, I’m using UberMenu from CodeCanyon

    Plugin Author Jan-Willem

    (@janwoostendorp)

    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 );
    Justin Fletcher

    (@justinticktock)

    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

    Plugin Author Jan-Willem

    (@janwoostendorp)

    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.

    Justin Fletcher

    (@justinticktock)

    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.

    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.

    Plugin Author Jan-Willem

    (@janwoostendorp)

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

    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.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Apply only to one custom post type’ is closed to new replies.