要将javascript 文件添加到wordpress theme,您有两种选择:
假设我们在主题的根目录中有一个jquery.js。
方法A)
在 wordpress 主题中打开 header.php 文件。在<head> 标签中添加这个:
<script src="<?php echo get_template_directory_uri(); ?>/jquery.js"></script>
方法 B)
在 wordpress 主题中打开functions.php 文件:
搜索 add_action( 'wp_enqueue_scripts', 'blahblah' ); 之类的内容,
如果存在,找到一个名称为blahblah 的函数并在其中添加此代码:
wp_enqueue_script(
'jquery',
get_template_directory_uri() . '/jquery.js', array(), '1.8.3', false );
否则:您应该添加function 和add_action 方法:
function scripts_styles() {
wp_enqueue_script(
'jquery',
get_template_directory_uri() . '/jquery.js', array(), '1.8.3', false );
}
add_action( 'wp_enqueue_scripts', 'scripts_styles' );
注意:将jquery 字符串替换为您的文件名。