0

Looking for to hide post on nav-menus page like in the picture.

I tried admin Adminimize but it's does not work. so I'm looking for a custom code to add on functions.php enter image description here

1 Answer 1

2

Keep in mind, there are two different ways to manage Menus in WordPress. One is through Appearance > Menus, which is the screen you're showing. The other is the Customizer.

Appearance > Menus : no coding required

You can prevent Posts from showing on a per-user basis. Just go to the top right corner of your screen, choose Screen Options, un-check Posts, and choose Screen Options again to close the panel.

Customizer

I'm not aware of a way to hide any registered post types specifically from the Customizer view. Hopefully someone with more Customizer know-how will reply if there is indeed a way.

Fortunately, this last section will remove Posts from both the Menus screen and the Customizer.

Changing a registered post type

When a post type is registered, there are arguments you can pass so that that post type will not appear in nav menus. Specifically, show_in_nav_menus.

Since Post is a built-in post type, you can't adjust where it's initially created. You'll need to use register_post_type_args to allow you to adjust the already-registered post type.

<?php
add_filter('register_post_type_args', 'wpse_remove_posts_from_nav_menus', 20, 2);
function wpse_remove_posts_from_nav_menus($args, $post_type) {
    if($post_type == 'post') {
        $args['show_in_nav_menus'] => false;
    }
    return $args;
}
?>

This should prevent Posts from appearing in either the menu management screen or the Customizer.

5
  • Thanks. I added your custom code. but it's break the page
    – Samuel
    Commented Jun 16, 2017 at 15:22
  • It was missing a semicolon. Updated above.
    – WebElaine
    Commented Jun 16, 2017 at 15:38
  • Yes after (false) . But i still have the same breaking page.
    – Samuel
    Commented Jun 16, 2017 at 15:44
  • It's work! just replace => false with = false . thanks again
    – Samuel
    Commented Jun 16, 2017 at 15:54
  • Code updated to working version - if this worked, perhaps you could mark as the answer.
    – WebElaine
    Commented Jun 19, 2017 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.