If you create a WordPress plugin, you may need to be able to configure certain settings or options in the admin dashboard. By adding a WordPress admin menu for your plugin you can alter the behavior or output of your plugin based on certain values. These values are saved by submitting data via a form which is then saved in the database.

Its important to note, WordPress shortcodes can also be used to customise the behavior or output of a plugin.

Create a menu link

A menu link is… well, its a link in the admin menu, that once clicked will direct the user to a settings page for your plugin. To create a menu link we use the WordPress add_action function with the admin_menu hook.

It should look like this:
add_action( 'admin_menu', 'create_my_plugin_link' );
or
add_action( 'admin_menu', array($this, 'my_plugin_call_back_function') );

create_my_plugin_link is the name of your PHP function where you set a few variables and pass them to another WordPress function called add_menu_page.

A typical implementation of an admin menu would look something like this:

add_action( 'admin_menu', 'create_my_plugin_menu_link' );

function create_my_plugin_menu_link() {
   $page_title = 'My Plugins Meta Title';
   $menu_title = 'My Plugins Link Text';
   $capability = 'manage_options';
   $menu_slug = 'my-plugin-settings';
   $function = 'my_plugin_call_back_function';
   $icon_url = 'dashicons-admin-tools';
   $position = 3;
   add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
}

If you are using PHP classes, dont forget to replace $function = 'my_plugin_call_back_function'; with $function = array($this, 'my_plugin_call_back_function');

The result of – add_menu_page()

Need a website, consultation or customisation? Let’s speak