Snippets: Set Default Values for Post Metabox Settings

The Page Settings Metabox is added to override default theme behavior which you can use theme filters to override. However, you can also set "defaults" for the page settings metaboxes so when you create a new post it auto selects these options. While in most situations we would recommend using theme hooks, this can be very useful as well. See the file at Total/framework/classes/post-metabox.php for the array of all settings so you can properly target them.

VERY IMPORTANT: In most cases using theme filters is the best solution the method below should be used only by those that know exactly what they are doing. Saving meta values on page creation can be difficult to update globally in the future. It is always best to use built-in filters to alter your theme functionality (see other snippets or request a new one if you can't find on).

function my_wpex_metabox_array( $array, $post ) {

	// Set Overlay Header to 'on' by default
	$array['header']['settings']['overlay_header']['default'] = 'on';

	// Disable title by default
	$array['title']['settings']['disable_title']['default'] = 'on';

	// Set default background style
	$array['title']['settings']['post_title_style']['default'] = 'background-image';

 	// Return fields -> IMPORTANT DO NOT DELETE!!
	return $array;

}
add_filter( 'wpex_metabox_array', 'my_wpex_metabox_array', 40, 2 );

Result:

All PHP snippets should be added via a child theme's functions.php file.