函数文档

wp_enqueue_scripts()

💡 云策文档标注

概述

wp_enqueue_scripts() 是 WordPress 中用于触发前端脚本和样式排队的 Hook 包装函数。它作为 do_action('wp_enqueue_scripts') 的封装,允许插件在 wp_head() 中早期执行,以便利用条件函数如 is_home() 或 is_page()。

关键要点

  • wp_enqueue_scripts() 是 do_action('wp_enqueue_scripts') 的包装函数,用于触发脚本和样式排队动作。
  • 该函数在 wp_head() 中首先运行,确保所有条件函数可用,便于插件通过 wp_enqueue_script() 排队前端资源。
  • 自 WordPress 2.8.0 版本引入,是核心 Hook 系统的一部分。

📄 原文内容

Wrapper for do_action( ‘wp_enqueue_scripts’ ).

Description

Allows plugins to queue scripts for the front end using wp_enqueue_script() .
Runs first in wp_head() where all is_home() , is_page() , etc. functions are available.

Source

function wp_enqueue_scripts() {
	/**
	 * Fires when scripts and styles are enqueued.
	 *
	 * @since 2.8.0
	 */
	do_action( 'wp_enqueue_scripts' );
}

Hooks

do_action( ‘wp_enqueue_scripts’ )

Fires when scripts and styles are enqueued.

Changelog

Version Description
2.8.0 Introduced.