Hello readers, If you are a WordPress developer, its essentials to know  ” How to add a new menu to Dashboard” when you are try to make any custom theme or plugin. Now i am going to show the functions and wp hooks for adding Custom Dashboard Menu.


Q 1 : What is WordPress Hooks?

WordPress hooks are arguably the basis of WordPress development, forming a large part of the core functionality and used by almost every plugin and theme available to date. WordPress hooks are, essentially, triggers of sorts that allow users to, with short snippets of code, modify areas a WordPress theme or plugin, or add their own code to various parts of WordPress without modifying the original files. An example of this could be along the lines of either “when WordPress chooses which template file to load, run our custom code” or “when you generate the content for each post, add social bookmarking links to the end of the content”. These examples will be expanded upon once we’re a bit more familiar with what exactly the different types of hooks are.

Hooks can be divided into “Action” and “Filter” hooks, the former allowing for insertion of custom code at various points (not unlike events in JavaScript) and the latter allowing for the manipulation of various bits of content (for example, the content of a page or blog post).

I shall discuss more about hooks later.

Step 1 :

Define A Function
function js_custom_menu(){
add_menu_page( page_title, menu_title, capability, menu_slug, function, icon_url, position );
/* add_menu_page(‘JS Login Activities’, ‘JS Login Act’, ‘manage_options’, ‘js-login-activities’, ‘general’, plugins_url(‘img/icon_16x16.png’, __FILE__),50); */

Step 2 :

Define A Function For Menu Page

function general(){
include( plugin_dir_path( __FILE__ ) . ‘yourpage.php’);
/* include( plugin_dir_path( __FILE__ ) . ‘panel/general.php’); */

Step 3 :

Add A Hook
add_action(‘admin_menu’, ‘js_plugin_menu’);