函数文档

print_embed_sharing_button()

💡 云策文档标注

概述

print_embed_sharing_button() 函数用于输出嵌入分享按钮所需的 HTML 标记。该函数在非 404 页面时生成按钮,否则直接返回。

关键要点

  • 函数功能:输出嵌入分享按钮的标记,包含链接和图标。
  • 条件检查:使用 is_404() 判断是否为 404 页面,若是则跳过输出。
  • 相关函数:涉及 esc_attr_e() 用于安全输出属性文本,is_404() 用于查询状态判断。
  • 版本历史:自 WordPress 4.4.0 版本引入。

代码示例

function print_embed_sharing_button() {
    if ( is_404() ) {
        return;
    }
    ?>
    <div class="wp-embed-share">
        <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>">
            <svg class="icon icon-share" aria-hidden="true" role="img">...</svg>
        </button>
    </div>
    <?php
}

📄 原文内容

Prints the necessary markup for the embed sharing button.

Source

function print_embed_sharing_button() {
if ( is_404() ) {
return;
}
?>
<div class="wp-embed-share">
<button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>">
<span class="dashicons dashicons-share"></span>
</button>
</div>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-includes/embed.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/embed.php#L1163">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/embed.php#L1163-L1174">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/esc_attr_e/">esc_attr_e()</a><code>wp-includes/l10n.php

Displays translated text that has been escaped for safe use in an attribute.

is_404()wp-includes/query.php

Determines whether the query has resulted in a 404 (returns no results).

Changelog

Version Description
4.4.0 Introduced.