Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created October 8, 2017 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/bb9333a9801d553b2b2815c9a37e7e79 to your computer and use it in GitHub Desktop.
Save damiencarbery/bb9333a9801d553b2b2815c9a37e7e79 to your computer and use it in GitHub Desktop.
Hide Specified Custom Post Types - with a little gotcha!!
<?php
// Based on: http://markwilkinson.me/2014/09/altering-registered-post-type-args/
// Hide some of the k-boom CPTs as they will not be used.
function ce_hide_some_cpts( $post_type, $args )
{
/* Only hide the post types listed in the array. */
if (!in_array($post_type, array('audio', 'event', 'portfolio', 'video'))) {
return;
}
// Skip 'Events Manager' plugin (it has 'description' set while 'Events' CPT does not).
if ('Display events on your blog.' == $args->description) {
return;
}
global $wp_post_types;
/* Hide CPT. */
$args->show_ui = false;
/* modify post type object to implement the changes */
$wp_post_types[ $post_type ] = $args;
}
add_action( 'registered_post_type', 'ce_hide_some_cpts', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment