Support

Account

Home Forums Feature Requests Separate Metabox Title Field

Solving

Separate Metabox Title Field

  • Right now if you set the style to Standard (WP Metabox), the metabox title uses the Custom Fields post title. It would be great to have a separate field for the metabox title (default can still be post title), so that as an Admin I can name the fields whatever I want, and then show a nice user-friendly title on the metabox.

    Thanks.

  • Any feedback on this?

    Thank you.

  • Hi @emrl,

    Thanks for the feature request.

    I have submitted this issue to Elliot for consideration and hopefully it will be added to the plugin’s development roadmap.

  • @acf-support Thanks James, I think the semi-recent addition of the “Description” field took care of this. Thanks though!

  • @acf-support contrary to @emrl I think the addition of the Description field did not fully take care of this 🙂 I mean that with a lot of custom field groups it helps to somehow group them by name (eg. ‘<template_name> Functionality’) so that the custom field group list is a little easier to navigate.

    But these group names do not look great when displayed on the actual page/post edit pages with metabox headers to the tune of ‘Homepage Template — Contact Us Section’ and ‘Options — Translations — For Email Use’ (options plugin). It’s usable but not 100% professional from a client’s perspective.

    To sum up: would love to see the ability to define metabox titles separately.

  • Hi @davidcie

    You should be able to change the meta box title by defining the field group title. Could you please test it out?

    Thanks 🙂

  • @acf-support thanks for your reply but I’m not sure you took the time to read my post. I think both myself and @emrl meant that we would like to see the ability to have two separate title fields: one that is used on the field group list and a separate one for the WP metabox.

    Not sure how I can describe it more specifically.

  • Hi @davidcie

    For something like that, you need to add an extra setting on the field group editor by using the acf/render_field_group_settings hook. After that, you need to loop through the field groups on the post/page editor screen. It should be something like this:

    // Add additional setting option for meta box title
    add_action('acf/render_field_group_settings', 'my_acf_add_field_group_title');
    function my_acf_add_field_group_title($field_group){
        acf_render_field_wrap(array(
            'label'            => __('Meta Box Title','acf'),
            'instructions'    => __('Add meta box title','acf'),
            'type'            => 'text',
            'name'            => 'metaboxtitle',
            'prefix'        => 'acf_field_group',
            'value'            => ( isset($field_group['metaboxtitle']) ) ? $field_group['metaboxtitle'] : '',
        ));
    }
    
    // Change the meta box title based on the new option
    function my_acf_change_metabox_title($field_groups){
        
        // get the current screen data
        $current_screen = get_current_screen();
        
        // only do this if the current screen is for a certain post type
        if( $current_screen->post_type == 'post' ){
            
            // loop through the available field groups
            foreach( $field_groups as $k => $field_group ){
                
                // if the new title is set and not empty, change the original title
                if( isset($field_group['metaboxtitle']) && !empty($field_group['metaboxtitle']) ){
                    $field_groups[$k]['title'] = $field_group['metaboxtitle'];
                }
            }
        }
        
        // return the data
        return $field_groups;
        
    }
    add_filter('acf/get_field_groups', 'my_acf_change_metabox_title');

    I hope this helps 🙂

  • James, it helps a lot, thank you. So much so that I packaged your code and created a plugin out of it so that people can use it more easily. It is available from GitHub here. (Tried to submit it to wordpress.org’s plugin directory but was told they do not take any framework plugins anymore.)

    Thanks again!

  • I’ve tried this with limited success.

    The function is firing but the fields aren’t changing? I can echo out the title and newer Metabox title but seems like the filter is coming in too late to affect the layout of the groups?

    Has anything changed with ACF Pro that could of affected this?

    And when I print_r($field_groups) I get the whole site’s fields and not just the ones for the post edit. Maybe this is normal?

  • I recently found that James’ solution to this problem (which I had been using successfully for some time) stopped working in my project. I did a little digging and discovered that two changes to the last line in his example are necessary to get it working again.

    First, the acf/get_field_groups filter was deprecated in ACF 5.7.11 in favour of acf/load_field_groups, so you’ll need to update accordingly. Simple enough, but it only gets you half way: If you dump the field group data before and after, you’ll see the titles changing properly, but for whatever reason those new titles don’t get used in the edit screen metaboxes.

    Second, you need to change the priority of the filter. WordPress filters default to a priority of 10, with numbers closer to 0 indicating earlier execution order. To ensure our changes don’t get overwritten, we actually want to apply this filter later, meaning we want a higher number. 20 seems to be working okay for me right now. I believe it became necessary to set priority in this case in ACF 5.7.10 with the addition of the _acf_apply_get_local_field_groups function, which also uses this filter at priority 20.

    TL;DR, James’ solution should work if we update the last line to read:
    add_filter('acf/load_field_groups', 'my_acf_change_metabox_title', 20);

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

The topic ‘Separate Metabox Title Field’ is closed to new replies.