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

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

| improve this answer | |
  • 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 Jul 5 '17 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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