Isaievskyi_Serhii
Isaievskyi_Serhii

Reputation: 481

How to remove button Add New Category (editor-post-taxonomies) in post editor

Add New Category - how to remove this link?

Add New Category - how to remove this link?

When creating a taxonomy, I use the default_term argument, so I no longer need the functionality to create and edit taxonomies, I only need the ability to select from those taxonomies that I created using default_term.

Removed from the menu - show_in_menu set to false. But I don't understand how to remove this link when creating a taxonomy?

Help remove the ability to edit in the post editor.

Upvotes: 0

Views: 663

Answers (3)

syscoid
syscoid

Reputation: 1

This case it's so simple, u can modified your theme functions.php add like this:

function custom_post_category() {
echo '<style>
    #category-adder {display: none !important;}
  </style>';
}
add_action('admin_head', 'custom_post_category');

refresh and try to remove capability for the user to create/edit post again new category for particular role

Upvotes: 0

Amin Abdolrezapoor
Amin Abdolrezapoor

Reputation: 1847

You can conditionally modify capabilities only on post edit screen to disallow new term creation, but yet keep allowing term assignments.

add_filter('register_taxonomy_args', static function (array $args, string $taxonomy) {
    global $pagenow;

    if (!in_array($pagenow, ['post.php', 'post-new.php'], true)) {
        return $args;
    }

    if ($taxonomy !== 'my-taxonomy') {
        return $args;
    }

    $args['capabilities'] = array_merge(
        isset($args['capabilities']) && is_array($args['capabilities'])
            ? $args['capabilities']
            : [],
        [
            'manage_terms' => 'do_not_allow',
            'edit_terms' => 'do_not_allow',
        ]
    );

    return $args;

}, 10, 2);

Upvotes: 0

S.Walsh
S.Walsh

Reputation: 3699

The following CSS selector can be used to target and hide the "Add New Category" button:

.components-button.editor-post-taxonomies__hierarchical-terms-add{
    display: none;
}

It's also possible to create your own Custom Taxonomy Selector component to replace the existing UI using JavaScript; as you need only to hide the button, I would use CSS in this case.

Upvotes: 0

Related Questions