'how to add custom link on wordpress admin sidebar
How to add custom link on wordpress admin sidebar without using plugins? For example, i want to add "Google.com" link. How should i do this?
I tried this: Added next code to admin-bar.php
function mycustomlink() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'parent' => 'new-content',
'id' => 'mycustomlinkId',
'title' => __('Custom link'),
'href' => admin_url( 'google.com'),
'meta' => false
));}
And added next code to class-wp-admin-bar.php
add_action( 'admin_bar_menu', 'mycustomlink', 900 );
but no results.
Solution 1:[1]
Add this to the bottom of your theme's function.php
add_action( 'admin_menu', 'linked_url' );
function linked_url() {
add_menu_page( 'linked_url', 'External link', 'read', 'my_slug', '', 'dashicons-text', 1 );
}
add_action( 'admin_menu' , 'linkedurl_function' );
function linkedurl_function() {
global $menu;
$menu[1][2] = "http://www.example.com";
}
Solution 2:[2]
For absolute links, just add this hook to your functions.php
file:
add_action('admin_menu', 'add_custom_menu_link');
function add_custom_menu_link()
{
add_menu_page('my_custom_link_1', 'Google', 'read', 'https://google.com/', '', 'dashicons-text', 1);
}
It also works for relative links, but you'll need to replace the initial slash with the HTML entity /
to prevent WordPress from stripping it out.
So, for example, you would have to use /books/563
instead of /books/563
.
add_action('admin_menu', 'add_custom_menu_link');
function add_custom_menu_link()
{
add_menu_page('my_custom_link_1', 'Google', 'read', "/books/563", '', 'dashicons-text', 1);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | yayheartbeat |
Solution 2 | Pikamander2 |