Skip to content

Snippet: Set Default Values for Post Metabox Settings

Important: Using theme filters is the best solution for altering settings. 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 one).

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.

// Set default theme meta values on post creation - NOT RECOMMENDED!!!!
add_filter( 'wpex_metabox_array', function( $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;

}, 40, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top