返回介绍

prepend_attachment()

发布于 2017-09-11 09:58:08 字数 2935 浏览 1078 评论 0 收藏 0

prepend_attachment( string $content )

Wrap attachment in paragraph tag before content.


description


参数

$content

(string) (Required)


返回值

(string)


源代码

File: wp-includes/post-template.php

function prepend_attachment($content) {
	$post = get_post();

	if ( empty($post->post_type) || $post->post_type != 'attachment' )
		return $content;

	if ( wp_attachment_is( 'video', $post ) ) {
		$meta = wp_get_attachment_metadata( get_the_ID() );
		$atts = array( 'src' => wp_get_attachment_url() );
		if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
			$atts['width'] = (int) $meta['width'];
			$atts['height'] = (int) $meta['height'];
		}
		if ( has_post_thumbnail() ) {
			$atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
		}
		$p = wp_video_shortcode( $atts );
	} elseif ( wp_attachment_is( 'audio', $post ) ) {
		$p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
	} else {
		$p = '<p class="attachment">';
		// show the medium sized image representation of the attachment if available, and link to the raw file
		$p .= wp_get_attachment_link(0, 'medium', false);
		$p .= '</p>';
	}

	/**
	 * Filters the attachment markup to be prepended to the post content.
	 *
	 * @since 2.0.0
	 *
	 * @see prepend_attachment()
	 *
	 * @param string $p The attachment HTML output.
	 */
	$p = apply_filters( 'prepend_attachment', $p );

	return "$p\n$content";
}

更新日志

Versiondescription
2.0.0Introduced.

相关函数

Uses

  • wp-includes/post.php: wp_attachment_is()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post-thumbnail-template.php: has_post_thumbnail()
  • wp-includes/post-thumbnail-template.php: get_post_thumbnail_id()
  • wp-includes/post-template.php: wp_get_attachment_link()
  • wp-includes/post-template.php: prepend_attachment
  • wp-includes/post-template.php: get_the_ID()
  • wp-includes/media.php: wp_video_shortcode()
  • wp-includes/media.php: wp_audio_shortcode()
  • wp-includes/post.php: wp_get_attachment_metadata()
  • wp-includes/post.php: wp_get_attachment_url()
  • wp-includes/post.php: get_post()
  • Show 7 more uses Hide more uses

Used By

  • wp-includes/embed.php: wp_embed_excerpt_attachment()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文