我正在word press中开发自定义主题。但我的java脚本文件无法正常工作。在Chrome控制台中,只有此消息显示JQMIGRATE: Migrate is installed, version 1.4.1
。但我的JavaScript文件无效。
Header.php代码
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Freelancer - Start Bootstrap Theme</title>
<?php wp_head(); ?>
<!-- Custom fonts for this template -->
<script src="https://use.fontawesome.com/e8beb482c3.js"></script>
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">
</head>
Footer.php代码
<div class="footer-below">
<div class="container">
<div class="row">
<div class="col-lg-12">
Copyright © Your Website 2017
</div>
</div>
</div>
</div>
</footer>
<?php wp_footer();?>
</body>
</html>
Function.php代码
<?php
add_theme_support('post-thumbnails');
function b2w_theme_styles() {
wp_enqueue_style('bootstrap_css' , get_template_directory_uri() . '/css/bootstrap.min.css');
wp_enqueue_style('style_css' , get_template_directory_uri() . '/style.css');
}
add_action ('wp_enqueue_scripts', 'b2w_Theme_styles');
function b2w_theme_js(){
wp_enqueue_script( 'contact_me_js', get_template_directory_uri() . '/js/contact_me.js', array('jquery', '', true) );
wp_enqueue_script( 'jqBootstrapValidation_js', get_template_directory_uri() . '/js/jqBootstrapValidation.js', array('jquery', '', true) );
wp_enqueue_script( 'jqueryeasing_js', get_template_directory_uri() . '/js/jquery.easing.min.js', array('jquery', '', true) );
wp_enqueue_script( 'freelancer_js', get_template_directory_uri() . '/js/freelancer.min.js', array('jquery', '', true) );
wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery', '', true) );
wp_enqueue_script( 'jquery_js', get_template_directory_uri() . '/js/jquery.min.js', array('jquery', '', true) );
wp_enqueue_script( 'popper_js', get_template_directory_uri() . '/js/popper.min.js', array('jquery', '', true) );
}
add_action ('wp_enqueue_scripts', 'b2w_theme_js');
?>
在index.php中,我使用此代码调用页眉和页脚以及我的html代码<?php get_header();?> , <?php get_footer(); ?>
答案 0 :(得分:0)
wp_enqueue_script('my-custom-script', get_template_directory_uri() .'/js/my-custom-script.js', array('jquery'), null, true);
自本文发布以来,WP脚本加载已经发生了很大变化。现在,只要其他脚本需要,WordPress就会自动为您加载jQuery。智能加载要求您在将其他JavaScript文件排入队列时将jquery指定为$ deps参数,例如: