I am trying to customize the ACF field widths via load_fields filters for certain field types. I successfully customized the image type with:
function acf_image_width($image_width) {
$i_width = '40';
if(empty($image_width['wrapper']['width'])) {
$image_width['wrapper']['width'] = $i_width;
} }
add_filter('acf/load_field/type=image','acf_image_width', 10);
This is pre-populating the image type wrapper attribute width with a value of 40.
For the WYSIWYG field, I did the same but I'm getting an error. I did this but I'm sure I'm getting the field type wrong for WYSIWYG.
function acf_wysiwyg_width($content_width) {
$c_width = '60';
if(empty($content_width['wrapper']['width'])) {
$content_width['wrapper']['width'] = $c_width;
} }
add_filter('acf/load_field/type=wysiwyg','acf_wysiwyg_width', 10);
I have tried acf_the_content
and that did not work either. Any help with the field type is appreciated.
CodePudding user response:
When using the acf/load_field
filter, as per the documentation link below...
https://www.advancedcustomfields.com/resources/acf-load_field/
The acf/load_field
filter function parameter is...
$field
(array)
The field array containing all settings.
So both of your function params are wrong. Don't be defining $image_width
and $content_width
as your functions parameter, as this will just confuse things, because you are actually passing full $field
settings as an array.
Just pass $field
param array as $field
instead, knowing the acf/load_field
filter will pass the field settings into $field
param as an array.
Then use $field
array to update, set or override current array values, and make sure you always return $field
at the end of your acf/load_field
filter function...
function acf_wysiwyg_width($field) {
// dump field param contents so you can see the returned data
// remove 2 lines below once your happy you know what your setting
var_dump($field);
exit;
// then use $field param like this to override the array value (if these keys actually exist)
$field['wrapper']['width'] = 60;
// you must always return function param $field for acf/load_field filter to finish the job!
return $field;
}
add_filter('acf/load_field/type=wysiwyg','acf_wysiwyg_width', 10);