Adding Menu in WordPress Admin – Theme Options

Adding Menu in WordPress admin is tricky and without proper documentation or help you can’t add it. Once i was beginner, i try and failed then i struggle to learn and here is the proper tutorial on how to add menu in WordPress admin. First you will see step by step tutorial then  a example […]

Share

Adding Menu in WordPress admin is tricky and without proper documentation or help you can’t add it. Once i was beginner, i try and failed then i struggle to learn and here is the proper tutorial on how to add menu in WordPress admin. First you will see step by step tutorial then  a example to practice.

To add administration menu in WordPress you need to use function called add_action() which is built-in function and needs two parameter First is a Hook which is explain next to this para, and a function which will you create yourself.

Hook to use:  To add admin menu in WordPress you need to use admin_menu hook.

How to use Add_Action?
Add_Action is WordPress function which add many features to your WordPress theme. It takes two parameters enclosed in single quote. The first parameter is hook which is explain above, second is your function name like function my_function(){ echo “something to return”;}

Now you have a functions and hook too. Here is more explanation how you will add this in your function file. First make your function you desired. After that write action as mention above. Suppose you made your function my_function , and you need to add admin menu so you have to write. See Example 1 and try it.

 add_action('admin_menu','my_function');
function my_function(){
 echo "something to return";
 }
 add_action('admin_menu','my_function');

Above example just init the function and tell WordPress to add something.But what and where?  your output of above example will simple text like “Something to Return” above the sidebar of admin panel. Now show something in your Nothing will show until you add pages in any page How to add pages inside your plugin page or any where in the WordPress menu.

Let’s assume you want to add option page in Appearance tab of WordPress for theme support (e.g. Theme Option) in admin panel.

function custom_content_of_theme(){
 echo "<h1>Theme Option Page is Ready.</h1>";
 }
 function option_for_theme(){
 add_theme_page( 'Two Clock Theme Page', ' Two Clock Options', 'edit_theme_options', 'my-unique-identifier', 'custom_content_of_theme' );
 }
 add_action('admin_menu','option_for_theme');

Explanation:

Function custom_content_of_theme, will return or echo the content like i echo H1 when you go to appearance and you will see the menu name called Theme Option, after clicking that it will show Heading saying “Theme Option is Ready”. You can put anything in that function like form or anything.
Theme Option WordPress

Function Option_for_theme, will tell create the sub item in Appearance Menu of your WordPress. Which has 5 parameters.
Create Theme Option in WordPress AdminFunction Add_Action which will tell WordPress to add run a function when rendering page. and it will read option_for_theme. and make a menu.

  1. The first parameter is Page Title or Title tag of the page.
  2. 2nd Parameter is Menu Title, which will be show to sub menu item identifier.
  3. 3rd will be the capabilities. See Documentation.
  4. 4th is Slug of Menu. Choose wisely and unique like my-unique-identifier (because it can’t be match other identifier because conflict appear.
  5. The last one is Function with Content in the last which you made the content like custom_content_of_theme. It can be anything form or anything.

This is the only way how to add menu in WordPress admin if you have any question or query then do ask question. Checkout a most important tutorial on.

How to Add Theme Options Using Plugin

Leave a Reply

Your email address will not be published. Required fields are marked *