I want to use the jQuery-ui .accordion
function in a WordPress child theme. So far I've:
我想在WordPress子主题中使用jQuery-ui .accordion函数。到目前为止,我已经:
- created a js file in my child theme directory and put it in no-conflict mode:
jQuery(document).ready(function($) { $( "#accordion" ).accordion(); });
- Enqueued the script into my functions.php file:
function myChild_scripts() { wp_enqueue_style( 'onepage-child-style', get_stylesheet_uri() ); wp_enqueue_script( 'onepage-child-accordion', get_stylesheet_uri() . '/js/accordion.js', array('jquery-ui-accordion', 'jquery'), 20150507, true );
- Added the
add_action
function:add_action( 'wp_enqueue_scripts', 'myChild_scripts' );
在我的子主题目录中创建了一个js文件并将其置于无冲突模式:jQuery(document).ready(function($){$(“#accordion”)。accordion();});
将脚本排入我的functions.php文件:function myChild_scripts(){wp_enqueue_style('onepage-child-style',get_stylesheet_uri()); wp_enqueue_script('onepage-child-accordion',get_stylesheet_uri()。'/ js / accordion.js',array('jquery-ui-accordion','jquery'),20150507,true);
添加了add_action函数:add_action('wp_enqueue_scripts','myChild_scripts');
However, the .accordion
function is also dependent on jquery-ui.css
. Don't I also need to include that in the enqueueing process? I can find no documentation that discusses inclusion of this file - or whether it's already part of WP core.
但是,.accordion函数也依赖于jquery-ui.css。我不是也需要在入队过程中加入它吗?我找不到讨论包含此文件的文档 - 或者它是否已经是WP核心的一部分。
1 个解决方案
#1
You can enqueue a stylesheet in the functions.php file. It may be something like this (assuming your file is in your theme directory, inside a css folder).
您可以在functions.php文件中排列样式表。它可能是这样的(假设您的文件位于主题目录中,位于css文件夹中)。
function my_styles()
{
wp_register_style( 'jquery-ui-style', get_template_directory_uri() . '/css/jquery-ui.css', 'all' );
wp_enqueue_style( 'jquery-ui-style' );
}
add_action( 'wp_enqueue_scripts', 'my_styles' );
Here's some reference.
这是一些参考。
#1
You can enqueue a stylesheet in the functions.php file. It may be something like this (assuming your file is in your theme directory, inside a css folder).
您可以在functions.php文件中排列样式表。它可能是这样的(假设您的文件位于主题目录中,位于css文件夹中)。
function my_styles()
{
wp_register_style( 'jquery-ui-style', get_template_directory_uri() . '/css/jquery-ui.css', 'all' );
wp_enqueue_style( 'jquery-ui-style' );
}
add_action( 'wp_enqueue_scripts', 'my_styles' );
Here's some reference.
这是一些参考。