How To Add Top and Sub-Menu Page On WordPress
How To Add Top Menu Page On WordPress
There is codex Example If you want to add a new top menu to the admin area, use the add_menu_page() function to create a menu.This example adds a new menu and page to the admin area. This example, create a plugin called Blogger For Your on WordPress.
add_menu_page ( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
Step 1: Create a hello menu Function
add_action('admin_menu', 'hello_menu');$page_title = 'hellp'
function hello_menu() {
add_menu_page (
'hellp',
'Blogger For Your',
'manage_options',
'my_page',
'admin_menu_page',
plugin_dir_url( __FILE__ ).'img/avatar-minus.png',
'23.65'
);
}
This is the heading for the page When you Create a menu function then click on menu there you see this title on your page.
$menu_title = 'Blogger For Your'
This is the title that will appear in the menu On the image you see there is a menu blogger for your with this you can write your menu title.
$capability = 'manage_options'
Capabilities is a security feature That Only users granted the manage_options capability will be allowed to see this menu page.
$menu_slug = 'my_page'
This is a unique name used by WordPress to refer to this menu page. If using classes pass this as an array( $this, ‘functionname’ ). For This Function you can add you sub menu there you want just paste $menu slug name on add_sub_menu $parent_slug.
NOTE: You can also call a file as in ‘myplugin/myplugin-admin.php’.
$function = 'admin_menu_page'
Name of the function called to render the menu page. NOTE: If the slug refers to a filename then the callback can be empty.for this function you can callback your created page.
$icon_url = plugin_dir_url( __FILE__ ).'img/avatar-minus.png'
This Function allow you to add your custom icon on your menu.
$position = '23.56'
This function $position allow you to add your menu were you want top or bottom.
Step 2: Register the hello_menu Function
Use the admin_menu action hook to register your function:
add_action( 'admin_menu', 'hello_menu' );
Step 3: Create the Page Using a Function
Create a callback function called admin_menu_page
function admin_menu_page() {?>
<h2>This is Just A example</h2>
<input class="widget-id" name="widget-id" type="hidden" value="archives-__i__" />
<input class="id_base" name="id_base" type="hidden" value="archives" />
<input class="widget-width" name="widget-width" type="hidden" value="250" />
<input class="widget-height" name="widget-height" type="hidden" value="200" />
<input class="widget_number" name="widget_number" type="hidden" value="2" />
<input class="multi_number" name="multi_number" type="hidden" value="3" />
<input class="add_new" name="add_new" type="hidden" value="multi" />
<?php}
Just Copy and paste This code On Your Plugin
add_action('admin_menu', 'hello_menu');
function hello_menu() {
add_menu_page (
'Hellp',
'Blogger For Your',
'manage_options',
'my_page',
'admin_menu_page',
plugin_dir_url( __FILE__ ).'img/avatar-minus.png',
'23.65'
);
}
function admin_menu_page() {?>
<h2>This is Just A example</h2>
<input class="widget-id" name="widget-id" type="hidden" value="archives-__i__" />
<input class="id_base" name="id_base" type="hidden" value="archives" />
<input class="widget-width" name="widget-width" type="hidden" value="250" />
<input class="widget-height" name="widget-height" type="hidden" value="200" />
<input class="widget_number" name="widget_number" type="hidden" value="2" />
<input class="multi_number" name="multi_number" type="hidden" value="3" />
<input class="add_new" name="add_new" type="hidden" value="multi" />
<?php}
How To Add Sub Menu Page On WordPress
function register_submenu_page() {Just Copy and paste This code On Your Plugin For Sub-menu
add_submenu_page( '$parent_slug', '$page_title', '$menu_title', '$capability', '$submenu_slug', 'my_submenu_page_callback' );
}
add_action( 'admin_menu', 'setup_theme_admin_menus' );
function setup_theme_admin_menus()
{
add_menu_page(
'Blogger For Your',
'Blogger For Your',
'manage_options',
'my_page',
'admin_menu_page'
);
add_submenu_page(
'my_page', // parent slug
'Front Page Elements 2', // page title
'Blogger Setting', // menu title
'manage_options', // capability
'my_page_sub', // slug
'my_submenu_page' // callback
);
// REMOVE THE SUBMENU CREATED BY add_menu_page
global $submenu;
unset( $submenu['my_page'][0] );
}
How To Add Top and Sub-Menu Page On WordPress
Reviewed by Unknown
on
5:58 AM
Rating:
No comments: