钩子文档

customize_controls_enqueue_scripts

💡 云策文档标注

概述

customize_controls_enqueue_scripts 是一个 WordPress 动作钩子,在 WP Theme Customizer 中用于注册自定义脚本和样式。它在 customize_controls_init 之后触发,允许开发者为 Customizer 控制界面添加前端资源。

关键要点

  • 这是一个动作钩子,用于在 Customizer 控制脚本加载时执行自定义代码。
  • 钩子没有参数,主要用于通过 wp_enqueue_script 或 wp_enqueue_style 函数注册脚本和样式。
  • 在 WordPress 3.4.0 版本中引入,适用于主题或插件开发。

代码示例

/**
 * Enqueue script for custom customize control.
 */
function custom_customize_enqueue() {
	wp_enqueue_script( 'custom-customize', get_template_directory_uri() . '/js/custom.customize.js', array( 'jquery', 'customize-controls' ), false, true );
}
add_action( 'customize_controls_enqueue_scripts', 'custom_customize_enqueue' );

📄 原文内容

Fires when enqueuing Customizer control scripts.

More Information

customize_controls_enqueue_scripts is an action hook triggered after the WP Theme Customizer after customize_controls_init was called, its actions/callbacks executed, and its own styles and scripts enqueued, so you can use this hook to register your own scripts and styles for WP Theme Customizer.

This action hook doesn’t have parameters.

Source

do_action( 'customize_controls_enqueue_scripts' );

Changelog

Version Description
3.4.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    /**
     * Enqueue script for custom customize control.
     */
    function custom_customize_enqueue() {
    	wp_enqueue_script( 'custom-customize', get_template_directory_uri() . '/js/custom.customize.js', array( 'jquery', 'customize-controls' ), false, true );
    }
    add_action( 'customize_controls_enqueue_scripts', 'custom_customize_enqueue' );