Add top-level menus and submenus to the WordPress background _php Tips

Source: Internet
Author: User

Add Settings page-add_menu_page function
add_menu_page (), this function is the back table to add a top-level menu first, that is, and "appearance", "plug-in" and other top-level menus.

The functions are described below:

<?php  
add_menu_page ($page _title, $menu _title, $capability, $menu _slug, $function, $icon _url, $position);  
Page_title page Title tag information  
//$menu _title menu title  
//capability permissions  
//menu_slug alias  
//function Executive function  
// Icon_url menu icon URL address  
//position the position of this menu item in the menu, warning: If the position properties of two menu items are the same, one of them may be overwritten  
?> 

For function arguments, this parameter is typically the name of the functions, and if you want to invoke the method of the class in the class, use the array (class name, function name) to invoke the form. If this argument is empty, the Menu_slug parameter can be a file path.

The position parameter of the function above, and the default menu item Location property is as follows:

2 Dashboard
 4 Separator
 5 Posts
 Media
 Links
 Pages
 Comments
 Separator
 appearance
 Plugins Users the
 Settings
 Separator

Well, or an example to explain, so as to Li Jufu. Create a new myfuntions.php in the default twenty ten topic, and then in the functions.php file include the editor to open our myfunctions.php.
Add new code:

<?php  
function test_function () {  
  add_menu_page (' title Caption ', ' menu title ', ' Edit_themes ', ' ashu_slug ', ' Display_ function ', ', 6;  
}  
 
function Display_function () {  
  echo '  
 

As you can see, the menu position is 6, compared to what you can find, it will be in the back of the "article" to see:

A top-level menu page has already appeared ...

Add Submenu item-add_submenu_page
the function of adding a submenu item is as follows:

<?php  
add_submenu_page ($parent _slug, $page _title, $menu _title, $capability, $menu _slug, $function);  
Parent_slug-the alias of the parent menu item  
//page_title--page title information  
//menu_title-Menu title  
//capability-permissions  
//menu_ slug-alias  
//function-functions performed  
?> 

In fact, with the first two tutorials, the use of this function is needless to say.

instance, or use the files in the two tutorials (create a new myfuntions.php in the default twenty ten topic, and include a new file in the functions.php file) With the editor to open our myfunctions.php, we have added a top-level menu item in the previous tutorial, and today we add a submenu item based on this top menu item, preserving yesterday's code, supplementing the new Code, Then the code in myfunctions.php is like this:

<?php   
function test_function () {   
  add_menu_page (' title Caption ', ' menu title ', ' Edit_themes ', ' ashu_slug ', ' Display_ function ', ', 6;   
}   
   
function Display_function () {   
  echo '  
 

The effect picture is this:

OK, Add submenu items complete ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.