Exclude Custom Post Type From Yoast

picu collections are never meant to be public, that is why we remove them from XML sitemaps, have robots meta directives set to noindex, etc..

(Short excursion: For various reasons we cannot set our collection post type to ‘public' => false, because they are public, as in they need to be displayed in the front end – just not for everyone.)

We try to support the most common SEO plugins. And by support I mean, make sure that users do not accidentally add their collections to search engines.

We implemented this for the Yoast SEO plugin a long time ago, but until now our custom post type still showed up in the Yoast settings. The settings for picu collections didn’t do anything, but they were still visible, which made it confusing for our users. (I even created an issue on GitHub years ago.)

We recently found this new filter wpseo_indexable_excluded_post_types, which not only allows us to excludes picu collection from being indexed by Yoast, it finally also did the trick of removing collection from the Yoast settings. 🥳

This is the code we used:

/**
 * Exclude collections from Yoast SEO indexable creation.
 *
 * @since 2.3.6
 *
 * @see https://developer.yoast.com/features/indexables/indexables-filters/#post_types
 *
 * @param array $excluded Array of excluded post types by name.
 * @return array The filtered post types.
 */
function picu_do_not_create_indexables_for_collections( $excluded ) {
	$excluded[] = 'picu_collection';
	return $excluded;
}

add_filter( 'wpseo_indexable_excluded_post_types', 'picu_do_not_create_indexables_for_collections' );