How to Add Multiple Custom Metaboxes in WordPress

The following code snippet will help you to add multiple custom meta boxes in WordPress.

Copy the code given below and add this code into your theme’s functions.php file or if you want to add meta boxes for your plugin then add this into your plugin-specific file.

// Add Multiple Custom Metaboxes 
//==================================================

function diwp_multiple_metaboxes(){

	//Custom Metabox 1
	add_meta_box(
					'diwp-metabox-1',
					'My Custom Metabox 1',
					'diwp_custom_metabox1_callback',
					'post'	
				);

	//Custom Metabox 2
	add_meta_box(
					'diwp-metabox-2',
					'My Custom Metabox 2',
					'diwp_custom_metabox2_callback',
					'post'	
				);

	//Custom Metabox 3
	add_meta_box(
					'diwp-metabox-3',
					'My Custom Metabox 3',
					'diwp_custom_metabox3_callback',
					'post'	
				);

}

add_action('add_meta_boxes', 'diwp_multiple_metaboxes');

//Callback Functions for multiple metaboxes

function diwp_custom_metabox1_callback(){

	echo "<strong>Hey! I am Your First Custom Metabox</strong>
		  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>";
}

function diwp_custom_metabox2_callback(){

	echo "<strong>Hey! I am Your Second Custom Metabox</strong>
		  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>";
}

function diwp_custom_metabox3_callback(){

	echo "<strong>Hey! I am Your Third Custom Metabox</strong>
		  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>";
}

The above code will add 3 custom meta boxes in the post screen with custom messages. You can modify the metabox’s callback function to fill different content in it.

To know more about metabox check

Owner of diveinwp.com, solely responsible for creating helpful, informative content about WordPress, a fulltime WordPress developer with 8+ years of hands-on experience in WordPress design and development.