The default_option_{$option} WordPress PHP filter allows you to modify the default value for a specific option.
Usage
add_filter( 'default_option_my_option', 'my_custom_default_value', 10, 3 ); function my_custom_default_value( $default_value, $option, $passed_default ) { // Your custom code here return $new_default_value; }
Parameters
- $default_value (mixed): The default value to return if the option does not exist in the database.
- $option (string): Option name.
- $passed_default (bool): Was
get_option()
passed a default value?
More information
See WordPress Developer Resources: default_option_{$option}
Examples
Change the default value for ‘my_option’
This example changes the default value for the ‘my_option’ to ‘my_default_value’:
add_filter( 'default_option_my_option', 'change_my_option_default', 10, 3 ); function change_my_option_default( $default_value, $option, $passed_default ) { return 'my_default_value'; }
Set a default value for ‘posts_per_page’
This example sets a default value for the ‘posts_per_page’ option:
add_filter( 'default_option_posts_per_page', 'change_posts_per_page_default', 10, 3 ); function change_posts_per_page_default( $default_value, $option, $passed_default ) { return 10; }
Modify the default value for ‘admin_email’
This example modifies the default value for the ‘admin_email’ option:
add_filter( 'default_option_admin_email', 'change_admin_email_default', 10, 3 ); function change_admin_email_default( $default_value, $option, $passed_default ) { return '[email protected]'; }
Set the default value for ‘thumbnail_size_w’
This example sets a default value for the ‘thumbnail_size_w’ option:
add_filter( 'default_option_thumbnail_size_w', 'change_thumbnail_size_w_default', 10, 3 ); function change_thumbnail_size_w_default( $default_value, $option, $passed_default ) { return 200; }
Modify the default value for ‘date_format’
This example modifies the default value for the ‘date_format’ option:
add_filter( 'default_option_date_format', 'change_date_format_default', 10, 3 ); function change_date_format_default( $default_value, $option, $passed_default ) { return 'F j, Y'; }