Home > CMS Tutorial > WordPress > How to call js in wordpress

How to call js in wordpress

藏色散人
Release: 2019-07-11 13:48:10
Original
5318 people have browsed it

How to call js in wordpress

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=&#39;text/javascript&#39; src=&#39;http://www.jquery.com/js/jquery/1.10.2/jquery-1.10.2.min.js&#39;></script>
Copy after login

or

<script src="<?php echo get_template_directory_uri(); ?>/js/jquery/1.10.2/jquery-1.10.2.min.js"></script>
Copy after login

2. Introduce the file into the theme's functions.php file, such as

function my_enqueue_scripts() {
if( !is_admin ) { // 前台加载的脚本与样式表
// 去除已注册的 jquery 脚本
wp_deregister_script( &#39;jquery&#39; );
// 注册 jquery 脚本
wp_register_script( &#39;jquery&#39;, get_template_directory_uri() . &#39;/js/jquery/1.10.2/jquery-1.10.2.min.js&#39;, false, &#39;1.0&#39;, false );
// 提交加载 jquery 脚本
wp_enqueue_script( &#39;jquery&#39; );
 } 
} 
// 添加回调函数到 init 动作上
add_action( &#39;init&#39;, &#39;my_enqueue_scripts&#39; );
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template