0

I would like to create a category or tag name that is available only to the admin(s) and not to the authors.

For example, I would like to create a category or tag called Exclusive Content.

Now only admins should be able to add this category or tag to their posts. Other users should not be able to see it or use it.

Is it possible?

1 Answer 1

0

Sure, you can restrict access to a tag with the following code:

add_action('save_post', 'remove_tags_function', 10, 2); 
function remove_tags_function( $post_id ){
    if(!current_user_can('manage_options')){ 
        $post_tags = wp_get_post_terms( $post_id, 'post_tag', array( 'fields'=>'names' ) );
        $pos = array_search( 'ExclusiveContent', $post_tags );
        if( false !== $pos ) {
            unset( $post_tags[$pos] );
            wp_set_post_terms ($post_id, $post_tags, 'post_tag');
        }
    }
}

So, with this code, whenever a normal user adds the tag ExclusiveContent, it will be removed upon save unless if the current user can manage_options. This code should be added to your functions.php file. You can find this file in your theme's folder.

2
  • I'm sorry but can you tell me where to put this code? :/
    – Sam DG
    Commented Nov 12, 2013 at 16:58
  • Absolutely, question updated.
    – Christine Cooper
    Commented Nov 12, 2013 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.