How to remove or unregistered Posts or Pages or Custom Content Type From the WordPress

Suppose Your Developed a WordPress Site and Based On the Roles You need to Give Access Which User are Capability to Use Create pages or Which User Are Capability To Create A Post.OR you Need to Remove the Menus from The Customizer you can Follow the below Steps or you need to Remove The Custome Content Type.
To Remove the Post from WordPress you Need to Following the Below Syntax

function unregister_post_types() {
    global $wp_post_types;
    if ( isset( $wp_post_types[ 'post' ] ) ) {   //Name of the Content type 
        unset( $wp_post_types[ 'post' ] );      //Name of the Content type that is (post)
        
          unset( $wp_post_types[ 'post' ] );
       return true;
    }
  return false;
}


add_action('init', 'unregister_post_types');

You Can Pase the Following Code at Function.php
To Remove The Pages From WordPress you Need to Follow the Below Syntax

function unregister_post_types() {
    global $wp_post_types;
    if ( isset( $wp_post_types[ 'page' ] ) ) {    //Name of the Content type that is (post)
        unset( $wp_post_types[ 'page' ] );      //Name of the Content type that is (post)
 
          unset( $wp_post_types[ 'page' ] );
       return true;
    }
  return false;
}
 
 
add_action('init', 'unregister_post_typs');

The above Syntax is Unregister the Post Types in A WordPress
You Can Pase the Following Code at Function.PHP
Similarly, You need to Remove any Custom type or core Custome you need to Give Content Type name
function unregister_post_types() {
    global $wp_post_types;
    if ( isset( $wp_post_types[ 'name_of_the_Content_type' ] ) ) {    //Name of the Content type that is need to remove
        unset( $wp_post_types[ 'name_of_the_Content_type' ] );       //Name of the Content type that is need to remove
 
          unset( $wp_post_types[ 'name_of_the_Content_type' ] );
       return true;
    }
  return false;
}
 
 
add_action('init', 'unregister_post_typs');

0 comments:

Post a Comment

Don't Forget to comment