简体   繁体   English

如何在WordPress管理菜单中添加基于用户的链接

[英]How to add a user based link in WordPress admin menu

I'm trying to ad a user specific menu item to the WordPress dashboard. 我正在尝试将用户特定的菜单项添加到WordPress仪表板。 Logged in users with a subscriber role anyway have reduced access, but I'd like to ad backend links to my jobs and dating and events dashboards. 无论如何,登录具有subscriber角色的subscriber减少访问权限,但我希望广告后端链接到我的jobsdatingevents仪表板。

Tried this in my functions php: 在我的函数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  0() {global $menu;
    $menu[1][2] = "https://adsler.co.uk/jobs-dashboard/";
}

It broke my site..... 它打破了我的网站.....

Your site broke because there is some syntax error in your code. 您的网站已损坏,因为您的代码中存在一些语法错误。 When defining second function you have function 0 . 定义第二个函数时,您有function 0 This should be function linkedurl_function . 这应该是function linkedurl_function If you fix this, URL will be there in the admin menu. 如果您解决此问题,则会在管理菜单中显示URL。

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] = "https://adsler.co.uk/jobs-dashboard/";
}

Alternative: If you want links inside the main menu like Dashboard , you can use following example. 备选:如果您想要主菜单内的链接,如Dashboard ,您可以使用以下示例。 In the following example, two links are added under Dashboard menu. 在以下示例中,在“仪表板”菜单下添加了两个链接。

add_action('admin_menu', 'wpso_custom_links_admin_menu');
function wpso_custom_links_admin_menu() {
    global $submenu;
    $submenu['index.php'][] = array( 'Link One', 'read', 'https://www.example.com/' );
    $submenu['index.php'][] = array( 'Link Two', 'read', 'https://asdf.com/' );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM