在wordpress中使用admin_menu动作回调中的post_type

时间:2014-07-18 05:45:33

标签: php html wordpress wordpress-plugin wordpress-theming

如何在post_type操作的回调函数中访问admin_menu

add_action( 'admin_menu' , 'remove_post_thumb_meta_box' );
function remove_post_thumb_meta_box()
{

    global $pagenow, $_wp_theme_features;
    if ( in_array( $pagenow,array('post.php','post-new.php')))
    {
        unset( $_wp_theme_features['post-thumbnails']);
    }
}

我只需要为post_type featured image metabox隐藏location

2 个答案:

答案 0 :(得分:0)

您可以这样做: -

将以下行添加到theme's functions.php文件中: -

remove_post_type_support( 'location', 'thumbnail' );

这只会影响您的location帖子类型。

希望它会对你有所帮助。

答案 1 :(得分:0)

您可以使用remove_meta_box( $id, $page, $context );功能删除元框。您可以查看我提供的链接

中的参数

为了更安全而不是抱歉,将您的功能挂钩到add_meta_boxes挂钩

function my_remove_meta_boxes() {
 if (is_admin()) {
  remove_meta_box('postimagediv', 'location', 'normal');
 }
}
add_action( 'admin_menu', 'my_remove_meta_boxes', 999 );