使jquery-ui元素进入Wordpress主题选项页面 [英] Enqueue jquery-ui elements in Wordpress theme option page
问题描述
嗯,我知道这是一个常见问题,但是几乎所有问题都像"2或3年前".由于Wordpress最近发生了一些重大的核心变化,因此最好获取更新的答案.
Well, I know this is a commonly asked question, but almost all of them like '2 or 3 years ago'. Since Wordpress had some serious core changes recently, thought it'd be better to get an updated answer.
我想做的就是将此jquery滑块添加到我的wordpress自定义管理页面中.
What I wanted to do is add this jquery slider to my wordpress custom admin page.
在当今的Wordpress中,是否内置了 jquery-ui ?还是我需要使用wp_enqueue_script
包含它,或者我应该使用一些外部URL CDN?
In today's Wordpress, is jquery-ui coming in built ? or I do need to include it using wp_enqueue_script
or I should use some external url CDN?
由于我正在使用Wordpress 4.2,因此能否请您告诉我添加此功能的正确方法?
Since I'm working on Wordpress 4.2, could you please tell me the proper way of adding this functionality?
谢谢!
推荐答案
是的,wordpress允许您添加多个依赖项.您可以在文档的 wp_enqueue_script()页上查看详细信息.
Yes the wordpress allows you to add multiple dependencies. You can check the details on the wp_enqueue_script() page in the documentation.
您要做的是在脚本中添加一个依赖项,以在其中初始化滑块.在您的脚本入队的functions.php
中,添加此
What you'd do is add a dependency to your script where you initialize your slider. In your functions.php
where you enqueue your scripts add this
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array('jquery', 'jquery-ui-slider'), '1.0.0', true );
example.js
是用于初始化滑块的脚本文件.它明确取决于jquery
和jquery-ui-slider
,因此您知道滑块将与jquery-ui的滑块ui组件一起使用.
example.js
is the script file where you initialize your slider. It depends explicitly on jquery
and on jquery-ui-slider
, so you know that the slider will work with the slider ui component of the jquery-ui.
它分为几部分,因此您不必占用整个页面上很重的jquery-ui
.
It's split into parts so that you don't have to enque entire jquery-ui
which is quite heavy on the page.
这篇关于使jquery-ui元素进入Wordpress主题选项页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!