enter image description here

I want to disable the default post types for user author in the wp-admin panel of the wordpress and display only custom post types.

For that i had got the code given below.

function remove_menus(){
$author = wp_get_current_user();
if(isset($author->roles[0])){ 
    $current_role = $author->roles[0];
}else{
    $current_role = 'no_role';
}
if($current_role == 'author'){ 
  remove_menu_page( 'index.php' );                  //Dashboard
  remove_menu_page( 'edit.php' );                   //Posts
  remove_menu_page( 'upload.php' );                 //Media
  remove_menu_page( 'edit.php?post_type=page' );    //Pages
  remove_menu_page( 'edit-comments.php' );          //Comments
  remove_menu_page( 'themes.php' );                 //Appearance
  remove_menu_page( 'plugins.php' );                //Plugins
  remove_menu_page( 'users.php' );                  //Users
  remove_menu_page( 'tools.php' );                  //Tools
  remove_menu_page( 'options-general.php' );        //Settings
}
}
add_action( 'admin_menu', 'remove_menus' ); 

The default post types disappear from the admin panel but the problem with the above code is that the pages are still accessible when the url is typed in and when loading admin panel from the top Dashboard appears.

I want the default post types blocked or page should not be loaded whereas custom post type page should load.

Thought the post type is disabled the pages load on type the url in address bar.

enter image description here

Read more here: Disable default posts (Posts,Pages,Comments and Media) in wp-admin


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: