我有这个滑块(环绕滑块http://foundation.zurb.com/docs/orbit.php ) 和wordpress插件(事件管理器http://wp-events-plugin.com/ ) 加载所有jQuery ui内容(
/**
* Enqueing public scripts and styles
*/
function public_enqueue() {
//Scripts
wp_enqueue_script(\'events-manager\', plugins_url(\'includes/js/events-manager.js\',__FILE__), array(\'jquery\', \'jquery-ui-core\',\'jquery-ui-widget\',\'jquery-ui-position\',\'jquery-ui-sortable\',\'jquery-ui-datepicker\',\'jquery-ui-autocomplete\',\'jquery-ui-dialog\')); //jQuery will load as dependency
//Styles
wp_enqueue_style(\'events-manager\', plugins_url(\'includes/css/events_manager.css\',__FILE__)); //main css
}
/**
* Localize the script vars that require PHP intervention, removing the need for inline JS.
*/
function localize_script(){
global $em_localized_js;
$locale_code = substr ( get_locale(), 0, 2 );
//Localize
$em_localized_js = array(
\'ajaxurl\' => admin_url(\'admin-ajax.php\'),
\'locationajaxurl\' => admin_url(\'admin-ajax.php?action=locations_search\'),
\'firstDay\' => get_option(\'start_of_week\'),
\'locale\' => $locale_code,
\'dateFormat\' => get_option(\'dbem_date_format_js\'),
\'ui_css\' => plugins_url(\'includes/css/ui-lightness.css\', __FILE__),
\'show24hours\' => get_option(\'dbem_time_24h\'),
\'is_ssl\' => is_ssl(),
);
)在网站的每个页面的顶部(
<link rel=\'stylesheet\' id=\'events-manager-css\' href=\'http://at.theplural.com/wp-content/plugins/events-manager/includes/css/events_manager.css?ver=3.4.2\' type=\'text/css\' media=\'all\' />
<script type=\'text/javascript\' src=\'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.core.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.widget.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.position.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.mouse.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.sortable.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.datepicker.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.autocomplete.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.resizable.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.draggable.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.button.min.js?ver=1.8.20\'></script>
<script type=\'text/javascript\' src=\'http://at.theplural.com/wp-includes/js/jquery/ui/jquery.ui.dialog.min.js?ver=1.8.20\'></script>
)。我基本上是试图阻止javascript加载到首页,或者理想情况下,只加载到->页面(“事件”)上所需的特定页面。我尽了最大努力让js“出列”,但没用
最合适的回答,由SO网友:jzatt 整理而成
如果只想在“事件”页面上对脚本排队,请更改以下代码以包含条件标记is_page()
function public_enqueue() {
//Scripts
wp_enqueue_script(\'events-manager\', plugins_url(\'includes/js/events-manager.js\',__FILE__), array(\'jquery\', \'jquery-ui-core\',\'jquery-ui-widget\',\'jquery-ui-position\',\'jquery-ui-sortable\',\'jquery-ui-datepicker\',\'jquery-ui-autocomplete\',\'jquery-ui-dialog\')); //jQuery will load as dependency
//Styles
wp_enqueue_style(\'events-manager\', plugins_url(\'includes/css/events_manager.css\',__FILE__)); //main css
}
将其更改为以下内容:
function public_enqueue() {
if( is_page(\'events\') ) { //Only load on the page "events"
//Scripts
wp_enqueue_script(\'events-manager\', plugins_url(\'includes/js/events-manager.js\',__FILE__), array(\'jquery\', \'jquery-ui-core\',\'jquery-ui-widget\',\'jquery-ui-position\',\'jquery-ui-sortable\',\'jquery-ui-datepicker\',\'jquery-ui-autocomplete\',\'jquery-ui-dialog\')); //jQuery will load as dependency
//Styles
wp_enqueue_style(\'events-manager\', plugins_url(\'includes/css/events_manager.css\',__FILE__)); //main css
}
}