Support

Account

Home Forums General Issues Followup: Dynamically Generated ACF Tab Names

Solved

Followup: Dynamically Generated ACF Tab Names

  • I was reviewing a previous post (closed) regarding giving users the ability to change the name of a tab for clarity: https://support.advancedcustomfields.com/forums/topic/dynamically-generated-acf-tab-names/

    John’s code works great, but unfortunately, it applies to all tabs and I’m confused how to target individual tabs directly. Is there a way to target each tab by it’s key and change the label?

  • Ah, nevermind, found another post and between the two, here’s the solution to target the key:

    add_filter('acf/prepare_field/key=field_key', 'custom_tab_format', 20);
    function custom_tab_format($field) { 
    if(get_field('this_field', $post->ID)) { 
      $field['label'] = get_field('this_field', $post->ID); 
    } 
    return $field; }
    
  • If you want to manage more than one tab, I used a unique function name for each instance:

    add_filter('acf/prepare_field/key=field_key', 'custom_tab_format', 20);
    function custom_tab_format($field) { 
    if(get_field('this_field', $post->ID)) { 
      $field['label'] = get_field('this_field', $post->ID); 
    } 
    return $field; }
    add_filter('acf/prepare_field/key=field_key', 'custom_tab_format_two', 20);
    function custom_tab_format_two($field) { 
    if(get_field('this_field', $post->ID)) { 
      $field['label'] = get_field('this_field', $post->ID); 
    } 
    return $field; }

    Hopefully this is helpful to others.

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

You must be logged in to reply to this topic.