How wordpress calls js
How wordpress calls js:
Generally, it is directly referenced in the theme's header.php file. Some themes will also load JS files through WP's own function wp_enqueue_scripts in the theme's functions.php file.
1. Directly introduce the file into the theme header.php file, such as
<script type='text/javascript' src='http://www.jquery.com/js/jquery/1.10.2/jquery-1.10.2.min.js'></script>
or
<script src="<?php echo get_template_directory_uri(); ?>/js/jquery/1.10.2/jquery-1.10.2.min.js"></script>
2. Introduce the file into the theme's functions.php file, such as
function my_enqueue_scripts() { if( !is_admin ) { // 前台加载的脚本与样式表 // 去除已注册的 jquery 脚本 wp_deregister_script( 'jquery' ); // 注册 jquery 脚本 wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery/1.10.2/jquery-1.10.2.min.js', false, '1.0', false ); // 提交加载 jquery 脚本 wp_enqueue_script( 'jquery' ); } } // 添加回调函数到 init 动作上 add_action( 'init', 'my_enqueue_scripts' );
For more WordPress technical articles, please visit the WordPress Tutorial column!
The above is the detailed content of How to call js in wordpress. For more information, please follow other related articles on the PHP Chinese website!