【发布时间】:2011-07-06 18:34:42
【问题描述】:
我有 6 个库的列表,我想加载到我的 wordpress 插件/主题中。目前它们都像这样添加到主题的标题中。
<script type="text/javascript" src="/wp-content/themes/mytheme/js/jquery.wijmo-open.1.2.0.min.js"></script>
我正在构建一个插件,它有自己的依赖于这些库的脚本。我想通过我想出的这个解决方案来运行,看看它是否符合 wordpress 标准。我需要将主题中的脚本排入队列,以便在插件中引用它们。
在主题标题中,我将所有<script src> 更改为<? wp_enqueue_script(); ?>。
wp_enqueue_script( 'my-jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js' );
wp_enqueue_script( 'my-jquery-ui-core', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js' );
wp_enqueue_script( 'raphael', '/wp-content/themes/mytheme/js/external/raphael.js', array('wijmo-jquery','wijmo-jquery-ui-core'));
wp_enqueue_script( 'jquery-glob', '/wp-content/themes/mytheme/js/external/jquery.glob.min.js', array('wijmo-jquery','wijmo-jquery-ui-core'));
wp_enqueue_script( 'jquery-bgiframe', '/wp-content/themes/mytheme/js/external/jquery.bgiframe-2.1.3-pre.js', array('wijmo-jquery','wijmo-jquery-ui-core'));
wp_enqueue_script( 'jquery-mousewheel', '/wp-content/themes/mytheme/js/external/jquery.mousewheel.min.js', array('wijmo-jquery','wijmo-jquery-ui-core'));
wp_enqueue_script( 'wijmo-open', '/wp-content/themes/mytheme/js/jquery.wijmo-open.1.2.0.min.js', array('wijmo-jquery','wijmo-jquery-ui-core','raphael','jquery-glob','jquery-bgiframe'));
在插件中,我现在可以引用我的插件 js 依赖项 jquery-glob、jquery-bgiframe 和 wijmo-open。
wp_enqueue_script( 'wee_broim_download_form', WP_PLUGIN_URL . '/wee-broim-download-form/js/script.js', array('jquery','jquery-ui-core','raphael','jquery-glob','jquery-bgiframe','jquery-mousewheel','wijmo-open','wijmo-complete'));
我知道 wordpress 有一些内置库,我可以使用 functions.php 指向 jquery、jquery ui cdn 等,但它对我来说只需重命名它们(my-jquery、my-jquery-ui) .我只是认为我逐步添加依赖项的方式有点混乱。我希望有办法对我的插件说,好吧,你最后加载。
【问题讨论】:
标签: php javascript jquery wordpress