Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP A handy guideline on adding custom menu item in WordPress admin

A handy guideline on adding custom menu item in WordPress admin

If you’ve been longing for gaining an additional control over your WordPress website’s admin bar, then you’ve landed on the right post. In this tutorial, I’ll be talking about the significance of adding a new custom menu item in the back-end along with the simple method of doing so the right way.

Guideline on adding custom menu item in wordpress admin

Guideline on adding custom menu item in wordpress admin

When does addition of a new custom menu item in WordPress admin serve handy?

The default WordPress admin dashboard comprises of some menus including Posts, Pages, Appearance, Plugins etc. which allow you to perform only the pre-defined functions. It is here that a custom menu item comes as a handy option. Unlike the hassles of installing a third-party plugin for doing a lot of other things with your menus; you can simply choose to create a custom menu item to accomplish your tasks within a remarkably short duration of time.

Now, let me make you familiar with the method of adding a new custom menu item in your WordPress back-end

Before proceeding ahead, let me make you acquainted with how the final outcome is going to be like. Well, the final product will be a custom menu item, linked to a page where you’ll be shown a refined list of users along with their roles. An ‘Edit’ link will be displayed against each user record, allowing you to modify the details for the respective user.
Before proceeding ahead with creation of a brand new menu item, you need to set the location for the same. For this, simply go to your admin dashboard-> Menus and select a preferred location for the secondary menu. Once you’re done with this, click on ‘Save’ button to save the settings.

The single-step method of adding custom menu item in WordPress admin

Simply open your WP theme’s functions.php file and add the below mentioned code to it:

<?php
add_action( 'backend_menu', 'create_new_custom_menu_page' );
 
function create_new_custom_menu_page(){
    add_custom_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'custompage', 'new_custom_menu_page','', 6 ); 
}
 
function new_custom_menu_page()
{
	$users = get_users();
?>
 
    <style type="text/css">
			table.usertable {
				font-family: calibri, verdana,arial;
				font-size:13px;
				color:#222222;
				border-width: 2px;
				border-color: #888888;
				border-collapse: collapse;
			}
 
			table.usertable th {
				background:#b3cfd1;
				border-width: 2px;
				padding: 6px;
				border-style: solid;
				border-color: #888888;
			}
 
			table.usertable td {
				background:#dcddc0;
				border-width: 2px;
				padding: 6px;
				border-style: solid;
				border-color: #888888;
			}
	</style>
 
    <h3>Custom Menu to display all users with their roles</h3>
		<table border="1" class="usertable">
				<tr>
						<th>No.</th>
						<th>User Name.</th>
						<th>User Role.</th>
						<th>Action.</th>
				</tr>
 
				<?php 
					$user_count=0;
 
					foreach($users as $user)
					{
						$user_count++;
				?>
			        <tr>
<td><?php echo $user_count;></td>	
<td><?php echo $user->user_login; ?></td>	
<td><?php echo $user->roles[0]; ?></td>	
<td><a href="<?php echo get_edit_user_link($user->ID);?>">Edit</a></td>	
				</tr>	
				<?php
					}
				?>
		</table>	
<?php
	}
?>

A brief on what the above code is all about

1. add_action( ‘admin_menu’, ‘register_my_custom_menu_page’ );

This is the hook that registers the ‘create_new_custom_menu_page’ function under the backend_menu hook.

2. function create_new_custom_menu_page()

{
add_custom_menu_page( ‘custom menu title’, ‘custom menu’, ‘manage_options’, ‘custompage’, ‘my_custom_menu_page’,”, 6 );
}

This function will call another function ‘add_custom_menu_page’ which will add the menu into the installed WordPress theme. The seven parameters defined for add_custom_menu_page function are explained below:

  • page title- this is the text that will be displayed along with the title tags of the custom menu page. When an admin user clicks on this custom menu, he/she will be able to view this text.
  • Menu title- This will the title that appears for the custom menu within the website’s admin panel.
  • Capability- This parameter will determine the capability that is required for displaying the custom menu to the user.
  • Menu slug- This parameter will be used for managing the menu slug that will be displayed on the URL of the page once the menu has been clicked
  • Function- Although this is an optional parameter, it displays the content stored for the custom menu page. In this tutorial, I’ve used the ‘new_custom_menu_page function which will generate the list of users, roles assigned to them along with an ‘Edit’ link for moderating the details of each user and his/her individual role.
  • Menu Icon- This is yet another optional parameter which serves as the right tool for managing the icon defined for the custom menu. In this tutorial, I’m not passing any image path for the menu and hence WordPress would assign a default image to the menu’s icon.
  • Menu Position- As the last(but optional) parameter, Menu Position enables you to manage the position of the menu. To put it simply, you can either choose to place the menu towards the top or the bottom; within the WordPress admin area.

With that you’re done with creating a new custom menu in your WordPress admin panel. The screen-shot for this new custom menu is shown below:

Creating a new custom menu in your WordPress admin panel

Creating a new custom menu in your WordPress admin panel

Final Thoughts

A custom menu renders you an absolute flexibility of managing your website in a much more refined manner as compared to how you’ve been doing it using the default WordPress admin menu. Working in synchronization with your specific requirements, a custom menu will serve as the right tool for embellishing your WordPress site/blog with brilliant add-ons.

Jan 27, 2015 Sophia Phillips
How to create new custom menu item in your wordpress back end?Know Simple Hacks To Systematize Media Library in WordPress
You Might Also Like:
  • How to create new custom menu item in your wordpress back end?
  • Create Custom Update Profile Page For WordPress Users
  • Add And Get Custom Field In WordPress
  • Add WordPress Login Form On Sidebar Or Custom Page
  • How To Hide/ Remove / Disable WordPress Top Navigation Bar
  • Show Error Message On WordPress Custom Login Template Page
  • WordPress Get All Custom Fields
  • Add More Extra Informations Or Fields To WordPress User Profile
  • C# Parse Item Value And Name In XML String
  • How To Change Default Home Page Of WordPress
Sophia Phillips

I am Sophia, my forte is WordPress and my work exists at the intersection of web development and technology blogging. Sophia is professionally associated with WordPress Web Development Company that has been taking huge strides in the web domain from quite a while now.

3 years ago PHPadd_action, add_custom_menu_page, get_edit_user_link, Wordpress, WordPress Custom Menu156
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
14,334 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
10,295 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
10,279 views
JQuery Allow only numeric characters or only alphabet characters in textbox
8,990 views
Firefox Can Not Connect To Proxy Server
Fix Can Not Connect To Proxy Server In Firefox, Google Chrome And Internet Explorer
5,869 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Magento Fatal error: Unsupported operand types
  • Ionic bower the name contains uppercase letters
  • PHP Magento Get Manufacturer Name And ID From Magento Product ID
  • Know Simple Hacks To Systematize Media Library in WordPress
  • A handy guideline on adding custom menu item in WordPress admin
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (26)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (140)
EMAIL SUBSCRIPTION

Sign up for our newsletter to receive the latest news and event postings.

Recommended
  • CDN
  • Hosting
  • Premium Themes
  • VPS
2014 © 4 Rapid Development