函数文档

_wp_admin_html_begin()

💡 云策文档标注

概述

_wp_admin_html_begin() 函数用于输出 WordPress 管理后台 HTML 页面的起始部分,包括处理 IE 兼容性和工具栏类。

关键要点

  • 函数输出管理后台 HTML 头部的开始标签,如 <html> 和 <head>。
  • 根据 is_admin_bar_showing() 设置 wp-toolbar 类,并针对 IE 浏览器添加 X-UA-Compatible 头。
  • 包含 admin_xml_ns Hook,允许在 HTML 标签内添加自定义操作。

代码示例

function _wp_admin_html_begin() {
    global $is_IE;

    $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';

    if ( $is_IE ) {
        header( 'X-UA-Compatible: IE=edge' );
    }

    ?>
    <!DOCTYPE html>
    <html <?php language_attributes(); ?> class="<?php echo $admin_html_class; ?>">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
    <?php do_action( 'admin_xml_ns' ); ?>

注意事项

  • 此函数自 WordPress 3.3.0 版本引入,主要用于内部模板函数如 iframe_header() 和 wp_iframe()。
  • 开发者通常不应直接调用此函数,而是通过相关 Hook 或模板函数进行扩展。

📄 原文内容

Prints out the beginning of the admin HTML header.

Source

function _wp_admin_html_begin() {
global $is_IE;

$admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';

if ( $is_IE ) {
header( 'X-UA-Compatible: IE=edge' );
}

?>

<html class="<?php echo $admin_html_class; ?>"
<?php
/**
* Fires inside the HTML tag in the admin header.
*
* @since 2.2.0
*/
do_action( 'admin_xml_ns' );

language_attributes();
?>
>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php echo get_option( 'blog_charset' ); ?>" />
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/template.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/template.php#L2653">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/template.php#L2653-L2679">View on GitHub</a></p></section>
<section class="wp-block-wporg-code-reference-hooks"><h2 id="hooks" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#hooks">Hooks</a></h2> <dl><dt class="wp-block-wporg-code-reference-title has-normal-font-size"><a href="https://developer.wordpress.org/reference/hooks/admin_xml_ns/"><span class="hook-func">do_action</span>( ‘admin_xml_ns’ )</a></dt><dd><p>Fires inside the HTML tag in the admin header.</p>
</dd></dl></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/language_attributes/">language_attributes()</a><code>wp-includes/general-template.php

Displays the language attributes for the ‘html’ tag.

bloginfo()wp-includes/general-template.php

Displays information about the current site.

is_admin_bar_showing()wp-includes/admin-bar.php

Determines whether the admin bar should be showing.

do_action()wp-includes/plugin.php

Calls the callback functions that have been added to an action hook.

get_option()wp-includes/option.php

Retrieves an option value based on an option name.

Show 2 moreShow less

Used by Description
iframe_header()wp-admin/includes/template.php

Generic Iframe header for use with Thickbox.

wp_iframe()wp-admin/includes/media.php

Outputs the iframe to display the media upload page.

Changelog

Version Description
3.3.0 Introduced.