admin_head
云策文档标注
概述
admin_head 是一个 WordPress 动作钩子,在所有管理页面的头部区域触发,主要用于添加 CSS 样式或 JavaScript 脚本。
关键要点
- admin_head 钩子在所有 WordPress 管理页面的 <head> 部分执行
- 常用于通过 wp_enqueue_style() 或内联 <style> 标签添加 CSS 样式
- 也可用于通过 wp_enqueue_script() 或内联 <script> 标签添加 JavaScript 脚本
- 示例展示了如何添加内联 CSS 样式到管理页面
代码示例
function dolly_css() {
echo "<style type='text/css'>
#adminmenu .wp-menu-image img {
padding: 0;
}
</style>";
}
add_action( 'admin_head', 'dolly_css' );
原文内容
Fires in head section for all admin pages.
Source
do_action( 'admin_head' );
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
Skip to note 4 content
lucspe
A basic example (from Hello Dolly plugin code):
function dolly_css() { // This makes sure that the positioning is also good for right-to-left languages $x = is_rtl() ? 'left' : 'right'; echo " <style type='text/css'> #dolly { float: $x; padding-$x: 15px; padding-top: 5px; margin: 0; font-size: 11px; } </style> "; } add_action( 'admin_head', 'dolly_css' );