Support

Account

Home Forums Add-ons Flexible Content Field Dynamic title for flexible content pane?

Solved

Dynamic title for flexible content pane?

  • I have a lot of flexible content fields in my project. In theory, there are 4-20 ‘page-section’ field-groups. Is there any magic way to include one of the field’s values – as part of the pane’s label? Just checking… : )

    Diagram one

    Diagram one

    Diagram one

    Diagram one

  • I think you’re looking for the acf/fields/flexible_content/layout_title filter. Assuming the name on that Title dropdown is just ‘title’ I think this should do it?

    
    add_filter('acf/fields/flexible_content/layout_title', function($title) {
        $ret = $title;
        if ($custom_title = get_sub_field('title')) {
            $ret = sprintf('<strong>%s</strong> <em style="font-size: 80%; opacity: 0.5">%s</em>', $custom_title, $title);
        }
    
        return $ret;
    });
    
  • Ooooh…. this is really cool!

    I had given each block a different key/name – so, I changed that to ‘block_title’ – so that I could keep it simple.

    `
    add_filter(‘acf/fields/flexible_content/layout_title’, function($title) {
    $ret = $title;
    if ($custom_title = get_sub_field(‘block_title’)) {
    $ret = sprintf($title . ‘: ‘ . ‘<strong>’ . $custom_title . ‘</strong>’);
    }
    return $ret;
    });
    `

    Hooray!!! So cool! Thanks @antishow !

    (for anyone else who finds this / the filter goes in your functions.php)

  • I meant to click ‘this solved my question’ on your answer – but botched it – and hit it on my own… : / — and can’t seem to undo it!

  • Is this also possible with a repeater field?

  • @storm-amber no, this is not a feature of repeater fields. Repeaters allow you do select which sub field is shown when collapsed.

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

The topic ‘Dynamic title for flexible content pane?’ is closed to new replies.