最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Hide default menu items in wordpress apearance > menus

programmeradmin1浏览0评论

In a wordpress theme, when i get to appearance > menus i can see some default options to add to my menu (pages, posts, custom-links, etc) and custom post-types. I only need Custom Links to be shown. And I need it to come with the theme, so unchecking the boxes at "screen options" is not an option. I imagine there must be some code I need to add to the theme's functions.php. I was advised to try this:

add_filter( 'hidden_meta_boxes', 'custom_hidden_meta_boxes' );
function custom_hidden_meta_boxes( $hidden ) {
    $hidden[] = 'pages';
    return $hidden;
}

but it doesn't seem to work.

Does anyone have an idea how to do it?

In a wordpress theme, when i get to appearance > menus i can see some default options to add to my menu (pages, posts, custom-links, etc) and custom post-types. I only need Custom Links to be shown. And I need it to come with the theme, so unchecking the boxes at "screen options" is not an option. I imagine there must be some code I need to add to the theme's functions.php. I was advised to try this:

add_filter( 'hidden_meta_boxes', 'custom_hidden_meta_boxes' );
function custom_hidden_meta_boxes( $hidden ) {
    $hidden[] = 'pages';
    return $hidden;
}

but it doesn't seem to work.

Does anyone have an idea how to do it?

Share Improve this question asked May 12, 2020 at 11:47 wp-lpwp-lp 1
Add a comment  | 

1 Answer 1

Reset to default 0

You will able to remove nav menu meta-box links from screen option but if you want to remove by custom code, please try below code, simply copy and paste this into your functions.php file:


function custom_remove_menu_link_types() {
    global $wp_meta_boxes;
    foreach ($wp_meta_boxes['nav-menus']['side'] as $nav_menus) {
        foreach ($nav_menus as $nav_id => $nav_menu) {
            // remove all menu's and keep only one
            if ($nav_id !== 'add-custom-links') {
                remove_meta_box($nav_id, 'nav-menus', 'side');
            }
        }
    }
}
add_action('admin_head-nav-menus.php', 'custom_remove_menu_link_types', 10);
发布评论

评论列表(0)

  1. 暂无评论