您应该放置.js
文件放入插件目录(可以是根目录或任何其他文件夹,如assets
或js
).
要在前端将JS和CSS文件排队,请执行以下操作:
function wp_357866_enqueue_frontend()
{
wp_enqueue_script(\'your-script\', get_template_directory_uri() . \'/path/to/js/your-script.js\', array(), null, true); // You should set the last parameter to \'true\' to load JS in the footer
wp_enqueue_style(\'your-style\', get_stylesheet_directory_uri() . \'/path/to/css/your-style.css\', array(), null);
}
add_action( \'wp_enqueue_scripts\', \'wp_357866_enqueue_frontend\' );
参考号:
wp_enqueue_scripts要将JS和CSS排入管理队列,请执行以下操作:
function wp_357866_enqueue_admin()
{
wp_enqueue_script(\'your-script\', get_template_directory_uri() . \'/path/to/js/your-script.js\', array(), null, true); // You should set the last parameter to \'true\' to load JS in the footer
wp_enqueue_style(\'your-style\', get_stylesheet_directory_uri() . \'/path/to/css/your-style.css\', array(), null);
}
add_action( \'admin_enqueue_scripts\', \'wp_357866_enqueue_admin\' );
参考号:
admin_enqueue_scripts