我创建了一个wordpress插件,我正试图将其上传到wordpress.org。我的问题是,社区不允许我从jQuery UI站点或本地加载jQuery UI。他们只接受使用Wordpress的jQuery UI。我试图使用此代码,但日期选择器不工作:
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
这是奇怪的,因为当我加载jQuery UI本地日期拾取器工作良好。
有人知道是怎么回事吗?
下面是添加wordpress插件脚本文件的示例代码
function my_admin_init() {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');//enables UI
wp_enqueue_script('jquery-ui-datepicker', $pluginfolder . '/jquery.ui.datepicker.min.js', array('jquery', 'jquery-ui-core') );
wp_enqueue_style('jquery.ui.theme', '/wp-content/themes/<themename>/js/jquery-ui-1.8.9.custom.css');
}
add_action('admin_init', 'my_admin_init');
,但要确保包括css文件和所有相关的图像(像任何jQuery UI安装)。
For wp-admin:
add_action( 'admin_enqueue_scripts', 'my_backend_scripts' );
For For End:
add_action( 'wp_enqueue_scripts', 'my_frontend_scripts' );
注意:my_backend_scripts &My_frontend_scripts是查询脚本和样式的函数。
。
function my_frontend_scripts() {
wp_enqueue_script(
'he-scripts',
plugins_url('js/scripts.js', dirname(__FILE__)),
array( 'jquery', 'jquery-ui-slider' )
);
wp_register_style('he-ex', plugins_url('css/style.css', dirname(__FILE__)));
wp_enqueue_style( 'he-ex' );
}