Ask your WordPress questions! Pay money and get answers fast! (more info)

Add menu item at the top of admin that links to URL WordPress

  • SOLVED

Hey, I need to know how to do the following:

1) Add a menu item to the top of the WP admin called "Support."
2) Link that to a specific URL
3) Change the background color and icon used

Thanks!!!

Answers (2)

2015-07-29

timDesain Nanang answers:

/**
* Constructs the admin menu.
*
* The elements in the array are :
* 0: Menu item name
* 1: Minimum level or capability required.
* 2: The URL of the item's file
* 3: undefined
* 4: Class
* 5: ID
* 6: Icon for top level menu : https://developer.wordpress.org/resource/dashicons/
*
* @global array $menu
* @name $menu
* @var array
*/


add_action( 'admin_menu' , 'wpq_admin_menu_support' );
function wpq_admin_menu_support() {
global $menu;
$menu[1] = array(
__('Support'),
'read',
'http://example.com',
'',
'menu-support',
'menu-support',
'dashicons-editor-help'
);
}

add_action( 'admin_head' , 'wpq_admin_menu_head' );
function wpq_admin_menu_head() {
?>
<style type="text/css">
.menu-support{background-color:#f90;}
</style>
<?php
}


Kyler Boudreau comments:

timDesain,

Your code worked - thank you!

2 questions if you're willing to answer:

1) How can I keep the font from turning blue on hover? I've tried everything with firebug and can't make it stay white.

2) Can the link open in a new tab?

Thanks!!!


timDesain Nanang comments:

You are welcome.
1. coloring

add_action( 'admin_head' , 'wpq_admin_menu_head' );
function wpq_admin_menu_head() {
?>
<style type="text/css">
#adminmenu .menu-support{background-color:#f90;color:#fff;}
#adminmenu .menu-support:hover{background-color:#ff0;color:#000;}
#adminmenu .menu-support .wp-menu-image:before{color:#fff;}
#adminmenu .menu-support:hover .wp-menu-image:before{color:#000;}
</style>
<?php
}


2. no, it can't. there is no parameter to assign the link as _blank target


Kyler Boudreau comments:

thanks so much! voting now.


Kyler Boudreau comments:

TimDesain,

Does this mean there could be a way for the new tab?

[[LINK href="http://wordpress.stackexchange.com/questions/147778/open-admin-bar-visit-site-in-a-new-window"]]http://wordpress.stackexchange.com/questions/147778/open-admin-bar-visit-site-in-a-new-window[[/LINK]]

2015-07-30

Ian Lincicome answers:

if u need help on this still, I wrote a detailed article about it at: http://jafty.com/blog/adding-a-custom-wordpress-admin-page-and-menu-item/
basically to add the menu item use:
add_action( 'admin_menu', 'addCustomMenuItem' );
function addCustomMenuItem(){
add_menu_page('Custom Admin Page Title', 'Custom Menu Title', 'manage_options', 'custom_admin_page_slug', 'pg_building_function','Icon_URL',3);
}//end addCustomMenuItem function.

Note: the 3 in the add_menu_page function all will force it to the top, but be careful it doesn't overwrite another menu item. I find that using 3 often puts it right below "dashboard"...

as far as linking to a specific url, I assume you mean a wordpress url, so u can do that in the call back function which would be the pg_building_function in the function call above.....but feel free to skype me to clarify and I'll be happy to explain. Also changing the icon can be done in the second last param in the add_menu_page function example above where i inserted "Icon_URL" before the 3.

...finally to change the background color, you can either do it in the image itself, or use firefox and right click and select "inspect code" to see what css you have to modify...again skype me and I'll explain further. I believe that should cover all points in your question;-)