WP中检测脚本是否已经注册的方法

WP_Scripts 继承自 WP_Dependencies
WP_Dependencies 有一判断是否已注册的方法.
如要判断Jquery是否已经注册:

1
2
3
4
5
6
global $wp_scripts;
$handle = 'jquery';
if(  ($wp_scripts instanceof WP_Scripts) &&  (!in_array($handle, $wp_scripts->done) || !$wp_scripts->query($handle)) )
{
//not registered yet,do the stuff ...
}

这个在做插件时比较有用。

更多
No Responses Post a comment

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS