Hướng dẫn thêm add menu trong WordPress admin panel
10th Aug 2021Creating menu
Add this code in functions.php file of your plugin or theme.
add_action('admin_menu', 'custom_menu');
In above line of code, first parameter is the hook we discuss about, Second parameter is name of callback function. In callback function you have to write what you want to alter in admin menu.
function custom_menu() { add_menu_page( 'Page Title', 'Menu Title', 'edit_posts', 'menu_slug', 'page_callback_function', 'dashicons-media-spreadsheet' ); }
As you can see in custom_menu() function I just used add_menu_page(). This function allow you to create a menu in admin sidebar and map that menu to a page.
In custom_menu() function
- First parameter is page title. the title tag of the page when the menu is selected..
- Second parameter is menu title. The text to be used for menu title.
- Third one is capability, The capability required for this menu to be displayed to the user. You can find a list of all WordPress capabilities here – https://codex.wordpress.org/Roles_and_Capabilities
- Fourth parameter is menu slug, which is used for creating page URL. Keep this unique.
- Fifth parameter is page callback function. The function to be called to output the content for this page.
- Sixth parameter is for icon, either you can provide a URL of image or you can choose predefined WordPress icons. https://developer.wordpress.org/resource/dashicons/
Reference – https://themes.artbees.net/blog/wordpress-custom-admin-pages/
Add new comment