Support

Account

Home Forums Feature Requests Filter for flexible content layouts Reply To: Filter for flexible content layouts

  • Thanks for all of the great direction guys! Wanted to add this here as well for anyone who wants to do this based on the page template. Still working on it, but this seems to be doing what we need for the moment:

    
    add_filter('acf/prepare_field/name=YOUR_ACF_FIELD_NAME', function($field) {
        
    global $post;
      
        $template = get_page_template_slug( $post->ID );
        $layouts = $field['layouts'];
        $field['layouts'] = array();
    
        if( $template == 'your-template-file.php' ) {
    
          foreach ($layouts as $layout) {
            if ($layout['name'] != 'specific_layout_1' && $layout['name'] != 'specific_layout_2') {
              $field['layouts'][] = $layout;
            }
          }
    
          return $field;
          
        } else {
    
          foreach ($layouts as $layout) {
              $field['layouts'][] = $layout;
          }
    
          return $field;
    
        }
    
    });