Contents
To add an external link into the menu, we just need to pick a top-level menu item by its key, and add a new submenu item using the external link instead of the relative page link. Here are the keys for the standard admin menu items (do a print_r () of the array to get any custom top-level items added by plugins):
How to add a custom link to a menu with a..?
On a custom URL in the Menu setup it is possible to use relative links to the [blogurl]. The secret is to start the relative URL with a single /. When a single / starts the custom URL the system will not prepend the typical http:// and then the current blogURL will be generated in the target URL at execution time.
Can you add external links to your menu in WordPress?
As you probably learned already, your menu can include links to all of the “Pages” you publish from your admin dashboard. But that’s not all you can add to your menu. You can also add links to posts, category archives, and external links leading to pages on other websites.
When you call add_submenu_page () or one of the section-specific functions like add_management_page () to add a menu item, internally WordPress adds an item to a submenu array that it uses later on to build the admin menu. The array is held in a global variable, so it’s easy enough to add items directly to it.
How to add a link to the Admin menu in WordPress?
WordPress has a good API for adding admin menu items. Unfortunately, it doesn’t allow you to specify a direct link to something, only a “slug” that links your menu item to a callback function to run when your menu item is selected. But fortunately, there’s a hack.
What is the hook for add submenu ( )?
The hook you should use is admin_menu. For $menu_slug please don’t use __FILE__ it makes for an ugly URL, and is a minor security nuisance. Within the rendering function $function you may want to access parameters you used in add_submenu_page (), such as the $page_title.
(string) (Required) The slug name for the parent menu (or the file name of a standard WordPress admin page). (string) (Required) The text to be displayed in the title tags of the page when the menu is selected. (string) (Required) The text to be used for the menu.
How is the Admin menu stored in WordPress?
You’ll see that the admin menu is stored in a nested array with an associative (keyed) array for the top level menu, and numerically indexed arrays for the second level menus. The second level menus are numerically indexed arrays of title, required capability and page slug.
Why do I need an external link icon on my website?
The external link icon helps a lot and many visitors will open the link in a new tab, but just to be on the safe side, we’ll make the link always open in a new tab. This will help you keep more of your hard-earned visitors on your site.
You cannot add items to the admin menus that point to external URLs, the menu addition functions do not support this, nor will they allow it. However, if you attach a callback onto the admin_menu hook, you can insert some items yourself manually and totally overcome the non-external URL problem.
Lets say we want to add a new Top-level menu called “WPOrg”. The first step will be creating a function which will output the HTML. In this function we will perform the necessary security checks and render the options we’ve registered using the Settings API. We recommend wrapping your HTML using a with a class of wrap.
How to add a link to a menu in Drupal 7?
Navigate to the node editing screen ( Node > Edit or http:) for the node you want to add to the menu (this is in the Content menu for Drupal 7). This can also be done when you first create the node. Click the checkbox marked Provide a menu link. The menu options will appear.