0
我想添加一个函数来添加一个脚本到wp_head()
,但我想这个脚本被加载的任何一个,但管理员。所以我使用条件if(!is_admin)
来实现这一点。但它一直为管理员加载。需要做什么修改? 这里是我使用的代码:只有在脚本不是管理员的情况下才能加载脚本?
function add_this_script_footer(){
if(!is_admin()) :
?>
<script type="text/javascript">
var message="My massage";
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
} else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")
</script>
<?php
endif;
}
add_action('wp_footer', 'add_this_script_footer');
要检查,如果用户是管理员,你会使用current_user_can( '管理员') - 或者,甚至更好,检查一个特定的能力。这是你需要的吗?它来自[这里](http://stackoverflow.com/questions/21239226/if-user-is-not-admin-deregister-jquery) – theoretisch
非常感谢'!current_user_can('administrator')' –