0

我有一个 wordpress 插件来生成一个 flickr 画廊。为避免与其他 jquery 插件冲突,我仅在尚未加载 jquery 时才加载它。但是这种方法的问题是,如果使用此方法加载 jquery,则颜色框不起作用。我在页面正文中看不到 cboxoverlay 和 colorbox 元素。

这是我的代码 -

if((typeof(jQuery) == 'undefined') || (jQuery.fn.jquery < '1.4.4')){
    var loadjQuery = document.createElement(\"script\");
    loadjQuery.setAttribute(\"src\",\"https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js\");
    var head = document.getElementsByTagName(\"head\")[0];
    head.appendChild(loadjQuery);
}

有什么线索可以解决这两个问题吗?

4

1 回答 1

2

您应该使用函数 enqueue_script。

“一种将 javascript 添加到 WordPress 生成的页面的安全方法。基本上,如果尚未包含脚本,请包含脚本,然后加载 WordPress 附带的脚本。”

基本上,这将允许您使用 WordPress 安全地包含脚本来完成工作。

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

如果这还不够详细,请告诉我,我可以详细说明

于 2011-06-16T16:51:56.747 回答