个性化阅读
专注于IT技术分析

如何从WordPress中的自定义帖子类型的编辑器页面中删除”添加新”按钮?

我有一个名为” jxta_home”的自定义帖子类型。我已使用以下代码从子菜单和编辑页面中删除了添加新按钮:

<?php
function disable_new_posts() {

    global $submenu;
    unset($submenu['edit.php?post_type=jxta_home'][10]);

    // Hide link on listing page
    if (isset($_GET['post_type']) && $_GET['post_type'] == 'jxta_home')  {
        echo '<style type="text/css">
        .page-title-action, .submitdelete { display:none; }
        </style>';
    } 
}

但是添加新按钮仍显示在内部编辑器页面上。我也想从那里删除它。如何将其从内部编辑器页面中删除?

在此处输入图片说明

#1


css有两个选项, 另一个将是编码。

选项1 :

function disable_new_posts() {
// Hide sidebar link
global $submenu;
unset($submenu['edit.php?post_type=jxta_home'][10]);

// Hide link on listing page
if (isset($_GET['post_type']) && $_GET['post_type'] == 'jxta_home') {
    echo '<style type="text/css">
    #favorite-actions, .add-new-h2, .tablenav { display:none; }
    </style>';
 }
}
add_action('admin_menu', 'disable_new_posts');

选项2:

你在传递注册帖子类型的参数时禁用添加新功能。

参数为:

create_posts’=>否

假设你有如下代码:

$args = array(
    'label'               => __( 'Custom Post Type', 'text_domain' ), 'description'         => __( 'Custom Post Type', 'text_domain' ), 'capability_type' => 'custom_post_type', 'capabilities' => array(
        'create_posts' => false
    )
);
register_post_type( 'custom_post_type', $args );

#2


你可以更改功能

使用map_meta_cap和create_posts将帖子类型注册为true;

$args = array(
     'label'               => __( 'Custom Post Type', 'text_domain' ), 'description'         => __( 'Custom Post Type', 'text_domain' ), 'capability_type' => 'custom_post_type', 'map_meta_cap'=>true, 'capabilities' => array(
         'create_posts' => true
     )
);
register_post_type( 'custom_post_type', $args );

然后, 你可以更改功能, 并在load-post.php标记上添加操作。

add_action('load-post.php', 'remove_add_button');

function remove_add_button() {
   if( get_post_type($_GET['post']) == 'MY-CUSTOM-POST-TYPE' ) {
     global $wp_post_types;

     $wp_post_types['MY-CUSTOM-POST-TYPE']->map_meta_cap = true;
     $wp_post_types['MY-CUSTOM-POST-TYPE']->cap->create_posts = false;
   }
}
赞(0)
未经允许不得转载:srcmini » 如何从WordPress中的自定义帖子类型的编辑器页面中删除”添加新”按钮?

评论 抢沙发

评论前必须登录!