Make a Plugin's Post Type Admin-Only
Removes the public pages, archive and search presence of a post type registered by a plugin or theme while keeping it editable in the admin.
Opens WPIDE on
Code
// Post types to hide from visitors.
$wpide_private_types = array( 'portfolio' );
add_filter( 'register_post_type_args', function ( $args, $post_type ) use ( $wpide_private_types ) {
if ( in_array( $post_type, $wpide_private_types, true ) ) {
$args['public'] = false;
$args['publicly_queryable'] = false;
$args['exclude_from_search'] = true;
$args['show_in_nav_menus'] = false;
$args['has_archive'] = false;
$args['rewrite'] = false;
$args['show_ui'] = true;
}
return $args;
}, 10, 2 );
Notes
Use for internal records that should never be public, then visit Settings > Permalinks once.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.