In the background of WordPress Add top menu and submenu of the function of the detailed, WordPress function in detail
Add Settings page-add_menu_page function
Add_menu_page (), the function is to add a top-level menu to the back of the table, that is, "appearance", "plug-in" and so on the same top menu.
The functions are described as follows:
<?php add_menu_page ($page _title, $menu _title, $capability, $menu _slug, $function, $icon _url, $position); Page_title Page Title Tag info //$menu _title menu title //capability permissions //menu_slug alias //function Execute function // Icon_url menu icon URL address //position the position of this menu item in the menu, warning: If the Location property of the two menu items is the same, one of them may be overwritten
For a function parameter, this parameter is typically the name of the functions, and if you want to invoke the method of the class in the class, it is called using the form array (class name, function name). If this parameter is empty, the Menu_slug parameter can be a file path.
The position parameter of the above function, the default menu item position property is as follows:
2 Dashboard 4 Separator 5 Posts Media Links ten Pages Comments-Separator appearance Ools Settings Separator
Well, it is still an example to explain, so as to Li Jufu. Create a new myfuntions.php in the default twenty ten theme, 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 ', ' menu title ', ' Edit_themes ', ' ashu_slug ', ' Display_ function ', ', 6); } function Display_function () { echo 'This is the Settings page
'; } Add_action (' Admin_menu ', ' test_function ');
As you can see, the menu position is 6, and a comparison can be found, and it will look at the back of the article:
A top-level menu page has appeared ...
Add a submenu item-add_submenu_page
The functions for adding sub-menu items are as follows:
<?php add_submenu_page ($parent _slug, $page _title, $menu _title, $capability, $menu _slug, $function); parent_slug-parent menu item alias //page_title--page title information //menu_title-Menu title //capability-permissions //menu_ slug-aliases //function-functions performed
In fact, with the first two tutorials, the use of this function is needless to say.
instance, or using the files from the two tutorials (create a new myfuntions.php in the default twenty ten theme and include the new file in the functions.php file) Using the editor to open our myfunctions.php, we have added a top-level menu item in the previous tutorial, and today we will add a submenu item based on this top-level item, preserving the code of yesterday, supplementing the new Code, After that, the code in myfunctions.php is:
<?php function test_function () { add_menu_page (' title ', ' menu title ', ' Edit_themes ', ' ashu_slug ', ' Display_ function ', ', 6); } function Display_function () { echo 'This is the Settings page
'; } Add_action (' Admin_menu ', ' test_function '); The following is the Add sub-menu item code add_action (' Admin_menu ', ' add_my_custom_submenu_page '); function Add_my_custom_submenu_page () { ///top menu slug is Ashu_slug add_submenu_page (' Ashu_slug ', ' submenu ', ' submenu ') , ' edit_themes ', ' ashu-submenu-page ', ' my_submenu_page_display '); } function My_submenu_page_display () { echo 'Output code for sub-menu items
'; }
Is this:
OK, add sub-menu items to finish ...
Articles you may be interested in:
- Wordpress Thickbox Click on the image to display the next picture of the modification method
- Tips for customizing the background Management interface color scheme in WordPress
- Add a code instance to the edit background of WordPress
- Add custom fields and background editing functional area to the article in WordPress
- Finishing some of the practical WordPress background mysql operation command
- WordPress Background to implement the image upload function of the example explained
http://www.bkjia.com/PHPjc/1091108.html www.bkjia.com true http://www.bkjia.com/PHPjc/1091108.html techarticle in the background of WordPress add top-level menus and sub-menu functions in detail, the WordPress function in detail to add the Settings page-add_menu_page function add_menu_page (), this function is to add the top of the table ...