Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Last active May 18, 2023 13:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackpyle/89adf9d41a3a47e28fbd255905f92d7e to your computer and use it in GitHub Desktop.
Save zackpyle/89adf9d41a3a47e28fbd255905f92d7e to your computer and use it in GitHub Desktop.
Add default image setting to ACF image fields #acf
<?php //ignore this line - for formatting only
// add default image setting to acf image field
add_action('acf/render_field_settings/type=image', 'add_default_value_to_image_field');
function add_default_value_to_image_field($field) {
acf_render_field_setting( $field, array(
'label' => 'Default Image',
'instructions' => 'Appears when creating a new post',
'type' => 'image',
'name' => 'default_value',
));
}
// show the default image
add_filter('acf/load_value/type=image', 'reset_default_image', 10, 3);
function reset_default_image($value, $post_id, $field) {
if (!$value) {
$value = $field['default_value'];
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment