您需要钩住3个不同的操作钩子才能完全隐藏默认的帖子类型。但是,仍然可以通过URL直接访问默认帖子。那么,让我们开始吧。
侧菜单
add_action( \'admin_menu\', \'remove_default_post_type\' );
function remove_default_post_type() {
remove_menu_page( \'edit.php\' );
}
新+的;在管理栏中发布链接
add_action( \'admin_bar_menu\', \'remove_default_post_type_menu_bar\', 999 );
function remove_default_post_type_menu_bar( $wp_admin_bar ) {
$wp_admin_bar->remove_node( \'new-post\' );
}
管理栏中的+新链接
function remove_add_new_post_href_in_admin_bar() {
?>
<script type="text/javascript">
function remove_add_new_post_href_in_admin_bar() {
var add_new = document.getElementById(\'wp-admin-bar-new-content\');
if(!add_new) return;
var add_new_a = add_new.getElementsByTagName(\'a\')[0];
if(add_new_a) add_new_a.setAttribute(\'href\',\'#!\');
}
remove_add_new_post_href_in_admin_bar();
</script>
<?php
}
add_action( \'admin_footer\', \'remove_add_new_post_href_in_admin_bar\' );
function remove_frontend_post_href(){
if( is_user_logged_in() ) {
add_action( \'wp_footer\', \'remove_add_new_post_href_in_admin_bar\' );
}
}
add_action( \'init\', \'remove_frontend_post_href\' );
快速草稿仪表板小部件
add_action( \'wp_dashboard_setup\', \'remove_draft_widget\', 999 );
function remove_draft_widget(){
remove_meta_box( \'dashboard_quick_press\', \'dashboard\', \'side\' );
}