wp_admin_bar_header()
概述
wp_admin_bar_header() 是一个已弃用的 WordPress 函数,用于输出管理工具栏的样式和脚本。自 WordPress 6.4.0 起,建议使用 wp_enqueue_admin_bar_header_styles() 替代。
关键要点
- 函数 wp_admin_bar_header() 已被弃用,从 WordPress 6.4.0 开始,应改用 wp_enqueue_admin_bar_header_styles()。
- 该函数检查当前主题是否支持 HTML5 样式属性,并据此输出相应的样式标签。
- 相关函数包括 current_theme_supports() 用于检查主题功能支持,_deprecated_function() 用于标记弃用函数。
注意事项
- 在开发中避免使用此弃用函数,以保持代码兼容性和最佳实践。
- 更新代码时,替换为 wp_enqueue_admin_bar_header_styles() 以确保功能正常。
Prints style and scripts for the admin bar.
Source
function wp_admin_bar_header() {
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_header_styles' );
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-includes/deprecated.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/deprecated.php#L5950">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/deprecated.php#L5950-L5956">View on GitHub</a></p></section>
<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/current_theme_supports/">current_theme_supports()</a><code>wp-includes/theme.php
Checks a theme’s support for a given feature.
_deprecated_function()wp-includes/functions.php
Marks a function as deprecated and inform when it has been used.
Changelog
| Version | Description |
|---|---|
| 6.4.0 | Deprecated. Use wp_enqueue_admin_bar_header_styles() instead. |
| 3.1.0 | Introduced. |