简体   繁体   English

如何添加指向运行我的 onclick 函数的 Wordpress 管理栏的链接?

[英]How can I add a link to the Wordpress Admin Bar that runs my function onclick?

I am wanting to add a link to the Wordpress admin bar that will eventually purge all cache.我想添加一个指向 Wordpress 管理栏的链接,最终会清除所有缓存。 At the moment I am trying to add the link to the admin bar but seem to be having problems.目前我正在尝试将链接添加到管理栏,但似乎有问题。

I have followed a few methods I had found on Google, but for some reason I couldn't get them to work.我遵循了在谷歌上找到的一些方法,但由于某种原因我无法让它们工作。 (I don't know if this is due to the examples being outdated with the version of Wordpress?) (不知道是不是因为例子随着Wordpress的版本过时了?)

Here is what I am using so far:这是我目前使用的:

function time_to_purge($wp_admin_bar) {
$args = array(
'id' => 'DaylesPurge',
'title' => 'Purge Cache',
'href' => '#',
'meta' => array(
'class' => 'DaylesPurge'
)
);
$wp_admin_bar->add_node($args);
}

add_action('admin_bar_menu', 'time_to_purge', 50);

function PurgeConfirmation() {
document.getElementById("PurgeConfirmation").innerHTML = "Are you sure you 
wish to purge the cash?";
}

[EDIT] Never-mind, this works perfectly. [编辑]没关系,这很好用。 It was a matter of a simple spelling mistake in my code that was preventing it from displaying.这是我的代码中一个简单的拼写错误导致它无法显示的问题。

function time_to_purge($wp_admin_bar) {
$args = array(
'id' => 'DaylesPurge',
'title' => 'Purge Cache',
'href' => '#',
'meta' => array(
'class' => 'DaylesPurge'
)
);
$wp_admin_bar->add_node($args);
}

add_action('admin_bar_menu', 'time_to_purge', 50);

function PurgeConfirmation() {
document.getElementById("PurgeConfirmation").innerHTML = "Are you sure you 
wish to purge the cash?";
}

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

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