在 functions.php 中排队脚本
如果要添加位于主题的 js/
文件夹中的 custom.js
脚本,则需要将其排入队列。在 functions.php
添加
<?php
add_action( 'after_setup_theme', 'yourtheme_theme_setup' );
if ( ! function_exists( 'yourtheme_theme_setup' ) ) {
function yourtheme_theme_setup() {
add_action( 'wp_enqueue_scripts', 'yourtheme_scripts' );
add_action( 'admin_enqueue_scripts', 'yourtheme_admin_scripts' );
}
}
if ( ! function_exists( 'yourtheme_scripts' ) ) {
function yourtheme_scripts() {
wp_enqueue_script( 'yourtheme_custom', get_template_directory_uri().'/js/custom.js', array( 'jquery' ), '1.0.0', true );
}
}
if ( ! function_exists( 'yourtheme_admin_scripts' ) ) {
function yourtheme_admin_scripts() {
wp_enqueue_script( 'yourtheme_custom', get_template_directory_uri().'/js/custom.js', array( 'jquery-ui-autocomplete', 'jquery' ), '1.0.0', true );
}
}