0

To disable custom fields except on category pages, how would I check if it's a category page?

Maybe it would be like this:

add_action( 'admin_menu', 'remove_custom_fields' );

function remove_custom_fields() {
    if(  /* code to check if page is not category page */){

        remove_meta_box('postcustom', 'page', 'normal');

    }

But I don't know how to do the check - I tried with

$screen = get_current_screen();
if($screen->taxonomy != 'category') { //etc}

but that didn't seem to work in the admin_menu action, but I could use it with the current_screen action, but that's the wrong place to remove the custom fields I guess.

---- EDIT ----

I realized that the category pages does not seem to have custom fields available , so it won't actually matter if I exclude the category pages from the removing of custom fields.

1 Answer 1

1

You Can use ACF Plugin to add a custom fields just for categories.

Add a new Field Group and set location to any of two settings:acf

1
  • I just realized that custom fields are not really available for category pages anyway, so my question was bad. Otherwise your answer may have worked , but wouldn't it be (!is_category()) since I want to exclude the category pages?
    – Galivan
    Commented Jul 5, 2017 at 22:26

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.