Home › Forums › Feature Requests › Separate Metabox Title Field › Reply To: Separate Metabox Title Field
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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.