Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use custom_menu_order filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 26, 2023
5 minutes read

WordPress hooks are like the secret ingredients in our favorite recipes – they spice things up and allow us to customize and extend our WordPress sites without altering the core files. One such hook is the custom_menu_order filter, which lets us customize the order of the WordPress admin menu items. Let’s dive into how you can use this hook to achieve your desired menu order.

Example 1: Setting Custom Menu Order

This example shows how to use the custom_menu_order filter to set a custom order for your admin menu items.

	add_filter( 'custom_menu_order', '__return_true' );
	add_filter( 'menu_order', 'weplugins_my_menu_order' );
	function weplugins_my_menu_order( $menu_order ) {
		return array( 'index.php', 'edit.php', 'edit.php?post_type=page', 'edit-comments.php' );
	}
	

Example 2: Modifying Custom Menu Order Defaults

Here’s how you can modify the default settings for the custom menu order using a custom function.

	function weplugins_modify_custom_menu_order_defaults($custom) { 
		// Update the $custom variable according to your website requirements and return this variable.
		// You can modify the $custom variable conditionally too if you want.
		return $custom; 
	}
	// add the filter
	add_filter( "custom_menu_order", "weplugins_modify_custom_menu_order_defaults", 10, 1 );
	

Example 3: Removing the Custom Menu Order Hook

Need to remove the custom menu order hook? Use the code snippet below.

	remove_filter( "custom_menu_order", "weplugins_modify_custom_menu_order_defaults", 10, 1 );
	

Make sure to provide the same callback function name, priority, and number of arguments when removing the hook callback.

Access Premium WordPress Plugins

Contact Us: If you need help with customization or have any questions regarding WordPress hooks, feel free to contact us. We’re always here to assist you with your WordPress needs.
Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.