Support

Account

Home Forums Add-ons Flexible Content Field Adding additional layout to flexible_content field in child theme Reply To: Adding additional layout to flexible_content field in child theme

  • I did some testing, not sure if this will help you but it’s what I came up with. The only problem I can see is if you have additional field in the group and this would put your flex field at the end of the group.

    
    <?php 
      add_action('init', 'add_a_layout', 20);
      function add_a_layout() {
        //echo 'here'; die;
        $layout = array (
          'key' => '56aab6d4e6272XXX',
          'name' => 'layout_2',
          'label' => 'layout 2',
          'display' => 'block',
          'sub_fields' => array (
            array (
              'key' => 'field_56aab6e3cba39XX',
              'label' => 'test field 2',
              'name' => 'test_field_2',
              'type' => 'text',
              'instructions' => '',
              'required' => 0,
              'conditional_logic' => 0,
              'wrapper' => array (
                'width' => '',
                'class' => '',
                'id' => '',
              ),
              'default_value' => '',
              'placeholder' => '',
              'prepend' => '',
              'append' => '',
              'maxlength' => '',
              'readonly' => 0,
              'disabled' => 0,
            ),
          ),
          'min' => '',
          'max' => '',
        );
        $field = acf_get_field('field_56aab6cdcba38');
        $field['layouts'][] = $layout;
        acf_remove_local_field('field_56aab6cdcba38');
        acf_add_local_field($field);
      }
    ?>