Add Page Setting Menu In Admin Side

In this article, I am going to show you how you can add your custom menu items in Admin Panel using WordPress.

Here I have mentioned the syntax of the Admin Menu() Function.

add_menu_page( $page_title,$menu_title,$capability,$menu_slug, callable $function = '',$icon_url = '',$position = null )
  • $page_title => (Required) When Menu is selected this text will be displayed.
  • $menu_title => (Required) Menu Title Text.
  • $capability => (Required) This Indicated this menu to be displayed to which user.
  • $menu_slug => (Required) Slug is the unique identification of menu
  • $function => (Callable Function)(Optional) This function to be called to display output content.
  • $icon_url => (Optional) The url of the icon to be used in menu.

Open the functions.php file from your theme folder.

And put the Below code in that functions.php file.

function admin_custom_menu_item() { 
	add_menu_page( 
		'Custom Menu', 
		'Custom Menu',
		'administrator',
		'custom_page_slug',
		'custom_page_slug',
	);
}

After that look into your Admin Panel. You will see “Custom Menu” in the Menu List.

For, Redirection of a particular page you need to create a callback page URL using the function. Here I have added the code below.

function custom_page_slug(){
    esc_html_e( 'Custom Page', 'domain-text' );  
}

Here I have added code for the Parent menu and submenu with page redirection.

function admin_custom_menu_item() { 
  add_menu_page( 
    'Custom Menu', 
    'Custom Menu',
    'administrator',
    'custom_page_slug',
    'custom_page_slug',
  );
  add_submenu_page( 
    'custom_page_slug', 
    'Page Setting Menu', 
    'Custom Menu',
    'administrator', 
    'custom_page_slug',
    'custom_page_slug'
  );
  add_submenu_page( 
    'custom_page_slug',
    'Custom Sub Menu',
    'Category',
    'edit_posts', 
    'custom_page_cat_slug',
    'custom_page_cat_slug'
  );
  add_submenu_page( 
    'custom_page_slug',
    'Custom Sub Menu',
    'Tags',
    'administrator',
    'custom_page_tag_slug',
    'custom_page_tag_slug'
  );
}
add_action('admin_menu', 'admin_custom_menu_item');

function custom_page_slug(){
    esc_html_e( 'Custom Page', 'domain-text' );  
}
function custom_page_cat_slug(){
    esc_html_e( 'Category Page', 'domain-text' );  
}
function custom_page_tag_slug(){
    esc_html_e( 'Tags Page', 'domain-text' );  
}

Here is the Image Preview of How the Admin Menu Looks Like.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories