$(document).ready(function(){proper in wordpress?
问题描述:
我想将library添加到wordpress中 所以我已经将所有的CSS和JavaScript库添加到Wordpress中 现在我必须运行时,下面的函数调用将执行一些Java代码。
$(document).ready(function(){
if (Modernizr.touch) {
// show the close overlay button
$(".close-overlay").removeClass("hidden");
// handle the adding of hover class when clicked
$(".img").click(function(e){
if (!$(this).hasClass("hover")) {
$(this).addClass("hover");
}
});
// handle the closing of the overlay
$(".close-overlay").click(function(e){
e.preventDefault();
e.stopPropagation();
if ($(this).closest(".img").hasClass("hover")) {
$(this).closest(".img").removeClass("hover");
}
});
} else {
// handle the mouseenter functionality
$(".img").mouseenter(function(){
$(this).addClass("hover");
})
// handle the mouseleave functionality
.mouseleave(function(){
$(this).removeClass("hover");
});
}
});
我如何可以添加到我的网页?
答
你应该在一个文件中添加此代码,并与wp_enqueue_scripts
增加。 function scripts_styles() {
与wp_enqueue_script
wp_enqueue_script('script-id', get_template_directory_uri() . '/js/main.js', array('jquery'));
添加CSS添加JavaScript和wp_enqueue_style
wp_enqueue_style('all-theme', get_template_directory_uri() . '/css/style.css.css');
} add_action('wp_enqueue_scripts', 'scripts_styles');