Support

Account

Home Forums Add-ons Flexible Content Field Value of a layout content block as a title

Helping

Value of a layout content block as a title

  • Hi, I use the following code to create named titles for layout content blocks

    function acf_change_layout_title( $title, $field, $layout, $i ) {
    	// layout name = template name
    	$layouts = ['intro-section','panel-slider','panel-grid','two-column','two-column-plus','one-column','center-column','basic-content','basic-header'];
    	if(in_array($layout['name'],$layouts)){
    			// layout is the complete setup without values
    			$field_key = $layout['sub_fields'][1]['key'];
    			$subtitle = $field['value'][$i][$field_key];
    			// field value has values based on field keys
    			if(!empty($subtitle)){
    				$title = '<strong>'. $subtitle .'</strong>&nbsp;&nbsp;&mdash;&nbsp;&nbsp;'.$title;
    			}
    	}
    	return $title;
    }
    add_filter( 'acf/fields/flexible_content/layout_title', 'acf_change_layout_title', 10, 4 );
    

    but this is not ideal, as a change or update (js event) changes the page the title disappears

    Is there a better way to achieve the same functionality?

  • I am using a simple layout title change using one of the layouts sub field, but mine is working when the value is changed/

    
    add_filter('acf/fields/flexible_content/layout_title/key=field_5c659c4616508', 'panel_title'), 20, 4);
    function panel_title($title, $field, $layout, $i) {
      if (get_sub_field('panel_name')) {
        $title = '<strong>'.get_sub_field('panel_name').'</strong> -- '.$layout['label'];
      }
      return $title;
    }
    

    Are you seeing any errors in your log? You need to turn on error logging https://codex.wordpress.org/WP_DEBUG. My assumption here is that there is something in your code that is triggering an error during the ajax request. Possibly in the way you are accessing the sub field values. Either that or there is something else on your site triggering an error during the request.

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

The topic ‘Value of a layout content block as a title’ is closed to new replies.