Last active
May 18, 2023 13:37
-
-
Save zackpyle/89adf9d41a3a47e28fbd255905f92d7e to your computer and use it in GitHub Desktop.
Add default image setting to ACF image fields #acf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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