从子主题中删除管理菜单项

0 wordpress custom-post-type

父主题注册了一个名为risen_event 的自定义帖子类型。我决定使用另一个日历插件,因此想从用户中删除这个管理菜单项。

在子主题中,我尝试了此功能,但没有用

if ( ! function_exists( 'unregister_post_type' ) ) :
function unregister_post_type( $post_type ) {
    global $wp_post_types;
    if ( isset( $wp_post_types[ $post_type ] ) ) {
        unset( $wp_post_types[ $post_type ] );
        return true;
    }
    return false;
}
endif;
Run Code Online (Sandbox Code Playgroud)

And*_*ren 5

如果您只想隐藏管理菜单项,请将其放在子主题的 functions.php 文件中:

function hide_menu_items() {
    remove_menu_page( 'edit.php?post_type=your_post_type_url' );
}
add_action( 'admin_menu', 'hide_menu_items' );
Run Code Online (Sandbox Code Playgroud)

将鼠标悬停在管理菜单项上并查看 URL 以获取要在该功能中使用的正确 URL。这不会注销帖子类型,只是隐藏管理菜单项。这样就可以保留帖子类型,以防您决定将来要使用它。