Support

Account

Home Forums General Issues Dynamically Generated ACF Tab Names

Solving

Dynamically Generated ACF Tab Names

  • Is it possible to have Tab names in the dashboard be updated with a field?

    For example, if an end-user is adding content to a section of their website, and the section’s title (e.g. an ACF text field) is named “Privacy Policy”, could the tab for that section update with that field’s text?

    This way, users are able to dynamically update their section names (Tab names) and it makes for a much cleaner experience all around.

    If this is not clear, please let me know and I’ll respond with screenshots.

  • Yes, you can do this using https://www.advancedcustomfields.com/resources/acf-prepare_field/. Any field setting can be dynamically altered.

  • Thank you for the reply.

    If it’s not too much to ask, could you go into a bit more detail, perhaps with an example relevant to my situation? I don’t think I’m quite grasping how to use this correctly.

    function my_acf_prepare_field( $field ) {
      $field['value'] = 'Test';
      $field['readonly'] = true;
      return $field;
    }
    
    add_filter('acf/prepare_field/type=tab', 'my_acf_prepare_field');

    I expected the above code to render all my Tab labels with the value of “Test”, but none of them changed.

  • You’re looking to alter the label of a tab field

    
    function my_acf_prepare_field( $field ) {
      global $post;
      if (get_field('some other field', $post->ID) {
        $field['label'] = get_field('some other field', $post->ID);
      }
      return $field;
    }
    
    add_filter('acf/prepare_field/type=tab', 'my_acf_prepare_field');
    
  • I haven’t forgotten about this. I’m still planning on trying to implement it, but I’m currently focusing on another problem. Just wanted to post an update, and say thank you to John Huebner for helping out so far.

  • Thanks John @hube2, that snippet just saved my day! excellent!

    P.S. f.y.i. – You missed a ‘)’ on line 3, right before the ‘{‘

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

You must be logged in to reply to this topic.