Home Forums Feature Requests Change Label Conditionally


Change Label Conditionally

  • I have found the need to change a label of a field conditionally. Lately I have just been trying to come up with a label that closely matches, but it would be nice not to have to.

    I need all other attributes of that field to stay the same.

    Is this possible without custom javascript, custom fileter, or can this be added as a feature.

    I am thinking something like this:

    'key' => 'field_type_label',
    'label' => array (
        array (
            array (
               'field' => 'field_type',
               'operator' => '==',
               'value' => 'video',
               'label' => 'Video Text'
        array (
            array (
               'field' => 'field_type',
               'operator' => '==',
               'value' => 'image',
               'label' => 'Image Caption'
    'name' => 'text',
    'type' => 'text',
  • I’m really not sure by looking at the code you provided what you’re trying to accomplish. You say you only want to change the label but I also see different field types.

  • The above is just an example.

    So lets say I have 2 fields:
    – format (radio buttons with two options [‘image’, ‘video’])
    – content (textarea)

    When the user (In the Admin) chooses format to be ‘image’ I would like the label for ‘content’ to be ‘Caption’.
    When the user chooses format to be ‘video’ I would like the label for ‘content’ to be ‘Description’.

    Sure, I could create two fields ‘caption’ and ‘description’ and set them conditionally based on ‘format’. The issue is then the user will have to copy their text and paste it in the next field. Which may not sound like a big deal, but when dealing with a repeater field where they have 20+ entries then it becomes one. Also I don’t want to have to add additional conditionals in my PHP code to retrieve the content.

    I can understand that this may be an issue when trying to figure out the best way to do this in the GUI, but my team and I don’t use the GUI. We build out all the fields using PHP. So for now I am just hoping that this can be done with PHP.

  • This isn’t something that can be done using PHP. When a repeater field is generated there is a ‘clone’ version of the row that is hidden. When you add a row ACF copies that hidden row to make the new row.

    There is nothing in ACF that will let you conditionally change the label of a field, or any other aspect of a field, based on another field. I’m not the developer, but I honestly don’t see features like this making it into ACF.

    The only way to accomplish what you want would be to add custom JavaScript. If you’re interested I can give you some ideas on how to accomplish this, but you said in the op that custom js was not an option.

  • Yes, this is just a feature request. I understand that JS is required to do this, but I am just asking that a dev can use PHP or JSON to build this functionality in just like we can do with ‘conditional_logic’. It would make my teams and I job much easier.

    I would still like this reviewed and considered.

  • To get this feature request to the developer submit a support ticket …. yes, the forum title says feature requests, but E does not get here much. He depends on other users so that he can spend his time working on ACF. As far as I know any feature requests sent in as a ticket are added to a list so they are easier to manage, although, I can’t be sure because I am not part of that system.

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

The topic ‘Change Label Conditionally’ is closed to new replies.