钩子文档

wp_print_styles

💡 云策文档标注

概述

wp_print_styles 是一个 WordPress 动作钩子,在 $handles 队列中的样式被打印之前触发。自 WordPress 3.3 起,不应用于排队样式或脚本。

关键要点

  • 这是一个动作钩子,在样式打印前执行,用于自定义样式处理。
  • 从 WordPress 3.3 开始,推荐使用 wp_enqueue_scripts 来排队前端脚本和样式。
  • 源文件位于 wp-includes/functions.wp-styles.php,由 wp_print_styles() 函数调用。
  • 引入于 WordPress 2.6.0 版本。

注意事项

避免使用此钩子来排队样式或脚本,应改用 wp_enqueue_scripts 钩子以确保正确的前端资源管理。


📄 原文内容

Fires before styles in the $handles queue are printed.

More Information

Since WordPress 3.3, wp_print_styles should not be used to enqueue styles or scripts.
See: https://make.wordpress.org/core/2011/12/12/use-wp_enqueue_scripts-not-wp_print_styles-to-enqueue-scripts-and-styles-for-the-frontend/

Use wp_enqueue_scripts instead.

Source

do_action( 'wp_print_styles' );

Changelog

Version Description
2.6.0 Introduced.