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!

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.