Set front-end field width | WordPress.org

Hello,

Thanks for the feedback!

Unfortunately this is not possible at the moment, because the width setting is wrapper inside a sub array called wrapper. Typically, it is defined like this in the $field array:

$field = array(
    'name'         => 'my_field',
    'key'          => 'field_6632c45281e1f',
    'label'        => 'My Field',
    'type'         => 'text',
    'required'     => true,
    'instructions' => 'my instructions',
    'wrapper'      => array(
        'width' => '50', // here
        'class' => '',
        'id'    => '',
    ),
);

The Advanced Settings feature is only comaptible with top level settings at the moment (instructions, required, label etc…).

There’s multiple ways to achieve it in PHP tho. Using the acf/prepare_field hook (see documentation):

add_filter('acf/prepare_field/name=text', 'my_prepare_text');
function my_prepare_text($field){
    
    // only on front-end
    if(!is_admin()){
        $field['wrapper']['width'] = '50'; // 50%
    }
    
    return $field;
    
}

If you’re using ACFE Form, you can directly set it inside your acfe_form() arguments, using the map argument (see documentation):

acfe_form(array(
    'name' => 'my-form',
    'map' => array(
        'field_6632c45281e1f' => array(
            'wrapper' => array(
                'width' => '50', // 50%
            ),
        ),
    ),
));

Or using the acfe/form/load_form hook if you prefer (see documentation):

add_filter('acfe/form/load_form/form=my-form', 'my_load_form');
function my_load_form($form){
    
    // change field wrapper width
    $form['map']['field_6632c45281e1f']['wrapper']['width'] = '50'; // 50%
    
    // return
    return $form;
    
}

It would be nice to make Advanced Settings compatible with sub arrays tho. I’ll add this feature in the next patch, and let users use “dot notation” to enter sub array settings.

Typically, you will be able to enter the following rule in the UI:

wrapper.width = 50

Hope it helps!

Have a nice day!

Regards.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer