Descriptive ACF Flexible Content Layout Titles
Shows each flexible content row's heading next to its layout name in the editor, so long pages built from sections are easy to scan.
Opens WPIDE on
Code
// Flexible content field name and the sub field shown in titles.
$wpide_acf_flex_field = 'page_sections';
$wpide_acf_flex_heading = 'heading';
add_filter( 'acf/fields/flexible_content/layout_title/name=' . $wpide_acf_flex_field, function ( $title ) use ( $wpide_acf_flex_heading ) {
$heading = function_exists( 'get_sub_field' ) ? get_sub_field( $wpide_acf_flex_heading ) : '';
if ( is_string( $heading ) && '' !== trim( $heading ) ) {
$title .= ' <span style="font-weight:400;opacity:.7">— ' . esc_html( wp_trim_words( $heading, 8 ) ) . '</span>';
}
return $title;
} );
Notes
Set the flexible content field name and the sub field holding each section's heading. Needs ACF PRO.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.