【发布时间】:2014-09-07 23:28:09
【问题描述】:
我是 Wordpress 的新手,我正在尝试将 js 和 css 文件以及 jQuery 包含到我创建的小部件中,我现在的代码是
<?php
class my_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID of your widget
'my_widget',
// Widget name will appear in UI
__('My Widget', 'my_widget_domain'),
// Widget description
array( 'description' => __( 'Blah blah ', 'my_widget_domain' ), ) );
}
// Creating widget front-end
// This is where the action happens
public function widget( $args, $instance ) {
//Some functionallity
}
} // Class wpb_widget ends here
// Register and load the widget
function wpb_load_widget() {
register_widget( 'my_widget' );
}
add_action( 'widgets_init', 'wpb_load_widget' );
?>
<link rel="stylesheet" href="<?php echo plugins_url();?>/my_plugin/js/jquery/jquery-ui.css">
<link rel="stylesheet" href="<?php echo plugins_url();?>/my_plugin/css/my_theme.css">
<script src="<?php echo plugins_url();?>/my_plugin/js/jquery/external/jquery/jquery.js"></script>
<script src="<?php echo plugins_url();?>/my_plugin/js/jquery/jquery-ui.js"></script>
<script src="<?php echo plugins_url();?>/my_plugin/js/myscript.js"></script>
如您所见,我在文件末尾包含了我的脚本,我读到了 wp_enqueue_script('jquery');,但我不确定在哪里包含我的脚本的正确位置。 wordpress 已经包含 jQueryUI 了吗?
【问题讨论】:
-
另外,请在发布您的问题之前进行搜索。这是您的解决方案。 http://wordpress.stackexchange.com/questions/48445/how-to-include-javascript-file-and-css-file-in-wordpress