仅当使用Side小部件时才将脚本入队

时间:2017-01-06 作者:MikeC

仅当使用小部件时,我如何使用以下脚本?

<?php

//sidedish slide script
function sidedish_slide_script() {

    wp_register_script(\'add-sd-js\', get_template_directory_uri() . \'/form-slider/jquery-1.8.2.min.js\', array(\'jquery\'),\'null\', true );
    wp_register_script(\'add-sd-custom\', get_template_directory_uri() . \'/form-slider/formslider.js\', array(\'jquery\'),\'null\', true );
    wp_register_style(\'add-sd-css\',get_stylesheet_directory_uri() . \'/form-slider/styles.css\', \'\',\'\',\'screen\' );


    wp_enqueue_script (\'add-sd-js\');
    wp_enqueue_script (\'add-sd-custom\');
    wp_enqueue_style (\'add-sd-css\');

}

add_action(\'wp_enqueue_scripts\',\'sidedish_slide_script\');


?>

1 个回复
SO网友:Gareth Gillman

is\\u widget\\u active是您想要的,例如。

function sidedish_slide_script() {
 wp_register_script(\'add-sd-js\', get_template_directory_uri() . \'/form-slider/jquery-1.8.2.min.js\', array(\'jquery\'),\'null\', true );
 wp_register_script(\'add-sd-custom\', get_template_directory_uri() . \'/form-slider/formslider.js\', array(\'jquery\'),\'null\', true );
 wp_register_style(\'add-sd-css\',get_stylesheet_directory_uri() . \'/form-slider/styles.css\', \'\',\'\',\'screen\' );

 if ( is_active_widget( false, \'widget_id\', $this->id_base, true ) ) {
  wp_enqueue_script (\'add-sd-js\');
  wp_enqueue_script (\'add-sd-custom\');
  wp_enqueue_style (\'add-sd-css\');
 }
}
add_action(\'wp_enqueue_scripts\',\'sidedish_slide_script\');

https://codex.wordpress.org/Function_Reference/is_active_widget

相关推荐

Dynamic Width of Widgets

好的,我在一个侧边栏中为最多6个小部件使用以下代码function s57d_sidebar1_params($params) { $sidebar_id = $params[0][\'id\']; if ( $sidebar_id == \'sidebar-1\' ) { $total_widgets = wp_get_sidebars_widgets(); $sidebar_widgets = count($total_wi