prepend_attachment()
最后更新于:2021-11-27 19:49:36
prepend_attachment( string$content)Wrap attachment in paragraph tag before content.
参数
- $content
-
(string) (Required)
响应
(string)
源文件
文件: gc-includes/post-template.php
function prepend_attachment( $content ) {
$post = get_post();
if ( empty( $post->post_type ) || 'attachment' !== $post->post_type ) {
return $content;
}
if ( gc_attachment_is( 'video', $post ) ) {
$meta = gc_get_attachment_metadata( get_the_ID() );
$atts = array( 'src' => gc_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'] = gc_get_attachment_url( get_post_thumbnail_id() );
}
$p = gc_video_shortcode( $atts );
} elseif ( gc_attachment_is( 'audio', $post ) ) {
$p = gc_audio_shortcode( array( 'src' => gc_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 .= gc_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 "$pn$content";
}