Support

Account

Home Forums Feature Requests Separate Metabox Title Field

Solving

Separate Metabox Title Field

    • emrl

    • December 19, 2014 at 10:57 am

    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.

    • emrl

    • March 14, 2015 at 5:57 am

    Any feedback on this?

    Thank you.

    • James

    • April 8, 2016 at 8:58 pm

    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.

    • emrl

    • April 9, 2016 at 3:34 am

    @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.

    • James

    • December 19, 2016 at 2:37 pm

    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 🙂

    • davidcie

    • December 19, 2016 at 10:07 pm

    @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.

    • James

    • December 20, 2016 at 11:55 am

    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!

    • v3nt

    • September 25, 2019 at 5:37 pm

    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?

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.