Support

Account

Home Forums General Issues Hiding/removing ACF custom (taxonomy) meta boxes in Gutenberg editor sidebar

Solving

Hiding/removing ACF custom (taxonomy) meta boxes in Gutenberg editor sidebar

  • With ACF I’ve created a custom post type that has a custom taxonomy field (also created with ACF). In the custom post type I’m also using Gutenberg editor.

    I’ve added the taxonomy field manually with a field group, but found that it is also present in the sidebar. I wanted to hide/remove the taxonomy from the sidebar, but I was not able to do it, even if I selected “No Meta Box” option at the “Visibility” tab of the custom field.

    After hours and hours of struggling to find out what I did wrong, I found many Gutenberg-ACF-MetaBox related issues on different blogs, forums and GitHub, and these metabox hiding” of issues seems to be present for years.

    However, I also found a GitHub comment from 2019 which – for me at least – actually provided a clean looking fix for this issue.

    Here is the comment:
    github . com /WordPress/gutenberg/issues/13816#issuecomment-470137667

    And here is the code:

    
    add_filter( 'rest_prepare_taxonomy', function( $response, $taxonomy, $request ) {
        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
        // Context is edit in the editor
        if( $context === 'edit' && $taxonomy->meta_box_cb === false ){
            $data_response = $response->get_data();
            $data_response['visibility']['show_ui'] = false;
            $response->set_data( $data_response );
        }
        return $response;
    }, 10, 3 );
    

    This code checks the taxonomies “meta_box_cb” property and allows modification of the taxonomy data right before it is returned from the rest API. And if the “meta_box_cb” is false, it sets “show_ui” of the metabox to false, so it will not show up in the sidebar.

    This actually makes the “No Meta Box” option working with Gutenberg!

    Is there any reason why this fix has not been implemented for four years?
    Are you planning to implement it in the near future?
    If not, at least it would be very important to add a note about this issue next to the “No Meta Box” option to save many hours of unnecessary debugging for the users.

    Waiting for an official statement about this.

    Best regards,
    Zs

  • If you are using ACF to create the taxonomy

    Advanced Settings => Visibility => Meta Box => No Meta Box

  • Hi John, thanks for your reply!

    What you wrote is working for posts without Gutenberg editor, but it is not working on post with Gutenberg enabled, this was my original problem.

    The solution I posted above fixes this issue.
    However, IMPORTANT UPDATE:
    Although this filter fixed the ACF-Gutenberg meta box hiding issue, I’ve run into other issues caused by this, which answers my question why this code is not implemented. The filter removed other random metaboxes of other plugins which made them unusable, so I think this solution needs more tweaking to work without affecting other things in a bad way.

  • The filter you posted is passing $taxonomy, check the taxonomy name to ensure it matches your custom taxonomy before making the changes?

    This is just a guess

  • Dude I have created an account just to say thank you! I tortured myself today with finding a solution for removing the taxonomy meta box.

  • IMPORTANT UPDATE [2]:
    Good news regarding to my comment here mentioning that the filter “removed other random metaboxes of other plugins”: I can confirm that it was just a bug with the specific plugin (I also reported that to the plugins developer) and it was NOT related to this fix, as I was encountering the problem randomly, even this filter completely removed from the website. So again, this fix solves the original problem without any side effects!


    @webdvp
    : You are welcome, I created this thread for this reason, to help others!


    @hube2
    : I can confirm that there seems to be no issues with this fix. I contacted your dev team to move forward to a fix.

  • Followup from the support:

    It appears that this [bug] is happening because the block editor uses a different API than the Classic Editor, and it does not register meta boxes. Instead, the metabox is registered as a React “Panel”.

    Actually, we have this report on our dev team’s issue-tracking list and we’re looking into removing that panel if the “Meta Box” setting is set to “No Meta Box”.

    Glad to know you got a fix in the meantime, I’ll be sharing that with the dev team as well.

    Hopefully this will have an official fix soon.

  • I’ve got a similar problem.

    A) added taxonomy via ACF (set to show MetaBox)
    B) added custom post type via ACF

    Problem is: no categories meta box when the REST Api is off for the taxonomy.

    Why do we need the REST Api of the taxonomy to show the meta box in the edit screen?

  • John, do you know if there is an official fix on the way?

    It’s been a few months, but I ended up here because the “Advanced Settings => Visibility => Meta Box => No Meta Box” still doesn’t seem to work in the block editor?

    Would appreciate an update from the official team!

  • @fzs, thanks for your bug fix inspiration!

    Somehow in WP 6.4.2 it didn’t work for me.

    When I removed $taxonomy->meta_box_cb === false it worked, but for all categories on all post types.

    But since I only want to hide a specific custom category, I simply replaced it with $taxonomy->name === 'event-category'.

    So the final modified version is this:

    add_filter( 'rest_prepare_taxonomy', function( $response, $taxonomy, $request ) {
        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
        // Context is edit in the editor
        if( $context === 'edit' && $taxonomy->name === 'event-category' ){
            $data_response = $response->get_data();
            $data_response['visibility']['show_ui'] = false;
            $response->set_data( $data_response );
        }
        return $response;
    }, 10, 3 );
  • @fzs Thank you for that fix. 10 months later it hasn’t been added to the plugin yet.


    @beat
    I haven’t had any issue in WordPress 6.5.3, categories and tags meta boxes in the built in Posts still appear.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.