Home › Forums › Feature Requests › Default Image option › Reply To: Default Image option
I never gave this much thought, although I do the same thing the same thing every time I need to have a default image. I always need to create custom code in the template to see if there’s an image and then do the default stuff.
Just did some testing and I can set a default image using a filter like this
add_filter('acf/load_field/name=image', 'set_default_image');
function set_default_image($field) {
$field['default_value'] = 258;
return $field;
}
Then I tried this, this code will add a default setting to every image field when you create it, it’s just a text field, I’ve just started playing with adding additional settings to ACF fields so I don’t know what else is possible.
add_action('acf/render_field_settings/type=image', 'add_default_value_to_image_field', 20);
function add_default_value_to_image_field($field) {
acf_render_field_setting( $field, array(
'label' => __('Default Image ID','acf'),
'instructions' => __('Appears when creating a new post','acf'),
'type' => 'text',
'name' => 'default_value',
));
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.