我想在管理栏中添加指向我的站点的链接,并使该链接成为管理栏中最左侧的项目。我可以在插件函数中添加与此相关的链接:
$wp_admin_bar->add_menu( array(
\'id\' => \'my-link\',
\'title\' => __(\'MySite\'),
\'href\' => site_url()
) );
但我想让它成为管理栏中最左边的链接,也就是说,一直在左上角。有没有办法做到这一点?我想在管理栏中添加指向我的站点的链接,并使该链接成为管理栏中最左侧的项目。我可以在插件函数中添加与此相关的链接:
$wp_admin_bar->add_menu( array(
\'id\' => \'my-link\',
\'title\' => __(\'MySite\'),
\'href\' => site_url()
) );
但我想让它成为管理栏中最左边的链接,也就是说,一直在左上角。有没有办法做到这一点?如果我是正确的,这些是默认位置:
wp\\u admin\\u bar\\u wp\\u menu-10
wp\\u admin\\u bar\\u my\\u sites\\u menu-20
wp\\u admin\\u bar\\u site\\u menu-30
wp\\u admin\\u updates\\u menu-40
wp\\u admin\\u bar\\u comments\\u menu-60
wp\\u admin\\u bar\\u new\\u content\\u menu-70 wp\\u admin\\u bar\\u edit\\u menu-80add_action(\'admin_bar_menu\', \'your_function_name\', 10);
这个10
应该将其置于adminbar中最左侧
目前我们正处于WP版本3.8,它仍然像一个魅力
添加示例:
function add_item($admin_bar) {
$args = array(
\'id\' => \'your-link\', // Must be a unique name
\'title\' => \'Yoursite\', // Label for this item
\'href\' =>__ (\'your_site_url\'),
\'meta\' => array(
\'target\'=> \'_blank\', // Opens the link with a new tab
\'title\' => __(\'Yoursite\'), // Text will be shown on hovering
),
);
$admin_bar->add_menu( $args);
}
add_action(\'admin_bar_menu\', \'add_item\', 10); // 10 = Position on the admin bar
我尝试了查尔斯的解决方案,但没有成功。我确实发现,您可以指定是否将内容添加到管理栏的哪一侧。
使用
add_action( \'admin_bar_menu\', \'yourfunctionname\' );
将您的新内容添加到管理栏左侧的默认内容之前。使用
add_action( \'wp_before_admin_bar_render\', \'yourfunctionname\' );
将在默认内容之后将新内容添加到管理栏的右侧。如果要完全重新组织管理栏,必须使用WP_Admin_Bar()
.
示例:
function reorder_admin_bar() {
global $wp_admin_bar;
// The desired order of identifiers (items)
$IDs_sequence = array(
\'wp-logo\',
\'site-name\',
\'new-content\',
\'edit\'
);
// Get an array of all the toolbar items on the current
// page
$nodes = $wp_admin_bar->get_nodes();
// Perform recognized identifiers
foreach ( $IDs_sequence as $id ) {
if ( ! isset($nodes[$id]) ) continue;
// This will cause the identifier to act as the last
// menu item
$wp_admin_bar->remove_node($id);
$wp_admin_bar->add_node($nodes[$id]);
// Remove the identifier from the list of nodes
unset($nodes[$id]);
}
// Unknown identifiers will be moved to appear after known
// identifiers
foreach ( $nodes as $id => &$obj ) {
// There is no need to organize unknown children
// identifiers (sub items)
if ( ! empty($obj->parent) ) continue;
// This will cause the identifier to act as the last
// menu item
$wp_admin_bar->remove_node($id);
$wp_admin_bar->add_node($obj);
}
}
add_action( \'wp_before_admin_bar_render\', \'reorder_admin_bar\');
我正在努力学习更多关于主题开发的知识,所以我创建了自己的主题,除了添加functions.php 并尝试用一些简单的方法进行更新,如:<?php add_theme_support(\'admin-bar\', array(\'menus\')); ?> 我明白了Server 500 ERROR 我无法访问Wordpress的任何部分,甚至连仪表板都无法访问。但一旦我删除functions.php 和刷新页面我的Wordpress又回来了,工作顺利。有什么神秘的fu