WordPress admin bar 添加自定义链接菜单

更新于 2024年3月2日 wordpress教程

要在WordPress的admin bar中添加自定义链接菜单,您可以在主题的functions.php文件中添加代码。以下是一个示例代码,演示如何添加自定义链接菜单:

function custom_toolbar_link($wp_admin_bar) {
  $plugin_manage = array(
    'id' => 'custom_link',
    'title' => 'imwpweb',    // 名称
    'href' => 'https://www.imwpweb.com',// 链接
  );
  $wp_admin_bar->add_node($plugin_manage); 
}
add_action('admin_bar_menu', 'custom_toolbar_link', 999);

在上述代码中,add_action('admin_bar_menu', 'custom_toolbar_link', 999);表示在admin bar菜单中添加一个名为custom_toolbar_link的函数,该函数的优先级为999。

然后,在custom_toolbar_link函数中,我们使用$wp_admin_bar->add_node()方法添加一个新的菜单项。在这个示例中,我们添加了一个顶级菜单项,其ID为custom_link,标题为“自定义链接”,链接为 https://www.imwpweb.com。

你可能还喜欢下面这些文章

wordpress怎么实现文章分页wordpress怎么实现文章分页

最近发现 有不少文章配上图片,写得比较长。’wp_more’,<if ( strpos( $content,'<if ( strpos( $content, ‘<

如何在wordpress中对the_content()和the_excerpt()设置字符限制如何在wordpress中对the_content()和the_excerpt()设置字符限制

php the_content();$content = $post->//limit content if (count($content)>

wordpress如何自定义短代码wordpress如何自定义短代码

wordpress实现自定义短代码。// @param $content 短代码里面的内容// @param $code 短代码function hello($atts, $content=null, $code=””) {

如何在WordPress文本小工具中运行PHP代码如何在WordPress文本小工具中运行PHP代码

WordPress文本小工具中可以添加任意HTML代码,但默认PHP代码添加到文本小工具中却不能运行,下面的这段代码很有用! $text = ob_get_contents();

如何将自定义 HTML 添加到 wp_nav_menu?如何将自定义 HTML 添加到 wp_nav_menu?

我熟悉 WordPress 并使用 WordPress 菜单系统。在您的functions.php创建一个类,使用与父类非常相似的方法来扩展Walker_Nav_Menu :

如何处理 WP 主题的 js 中文本的翻译如何处理 WP 主题的 js 中文本的翻译

wp_register_script( ‘some_handle’, ‘< wp_localize_script( ‘translations’, ‘DialogMessages’, [ ‘Are you sure you wan

wordpress如何跳转页面wordpress如何跳转页面

从wordpress后台登入自己的博客网站。仪表盘中找到页面——新建页面。填写页面名称——修改固定链接——在文本情况下输入以下代码:【代码如图中所示】简单便捷好用【图中为演示地址】

wordpress如何在一个页面显示所有文章wordpress如何在一个页面显示所有文章

让WordPress一个页面显示全部分类的文章cat=’ . $cat->php echo $cat->a href=”<$cats = get_categories(array(‘include’ =>