Completely disable Portfolio CPT

Hi,

I am aware of the way to hide Portfolio using this code:

add_action('admin_head', 'hide_portfolio');

function hide_portfolio() {
  echo '<style>
    li#menu-posts-x-portfolio {
    display: none;
}
  </style>';
}

However, that does not remove it from the system. It is still registered. This leads to useless sitemap and other seo stuff using SEO plugins (needs to be turned-off manually), and clogging all plugins that list Custom Post Types for various uses.

For example, Essential Grid does have Demo CPT, but it also has an option in settings to turn it off.

I suggest that That Theme Options has a toggle where Portfolio can be turned off completely, for those who don’t use it.

In the meantime, is there a magic code to turn it off completely? :slightly_smiling_face:

Thanks!

2 Likes

Hi There,

You can use this code to delete the portfolio custom post type:

function delete_post_type(){
    unregister_post_type( 'x-portfolio' );
}
add_action('init','delete_post_type', 9999);

This code above should be put under functions.php file locates in your child theme.

Regards!

2 Likes

Thanks!

That removed the CPT, but “Portfolio Tags” and “Portfolio Categories” are still present. (Yoast is showing them as Taxonomies to deal with).
Any way to remove those too?

Thanks again!

Hi Misho,
You might need to unregister these taxonomies as well, so please replace the previously mentioned code snippet with this one:

function delete_post_type(){
    unregister_post_type( 'x-portfolio' );
    unregister_taxonomy( 'portfolio-tag' );
    unregister_taxonomy( 'portfolio-category' );
}
add_action('init','delete_post_type', 9999);

Thanks.

6 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.