prepend_attachment( string $content )
Wrap attachment in paragraph tag before content.
Description Description
Parameters Parameters
- $content
-
(string) (Required)
Return Return
(string)
Source Source
File: wp-includes/post-template.php
1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 | 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" ; } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |