prepend_attachment

Wrap attachment in paragraph tag before content.

Description

(string) prepend_attachment( (string) $content ); 

Returns (string)

Parameters (1)

0. $content (string)
The content.

Usage

  1. if ( !function_exists( 'prepend_attachment' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // The content. 
  5. $content = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = prepend_attachment($content); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post-template.php  
  1. function prepend_attachment($content) { 
  2. $post = get_post(); 
  3.  
  4. if ( empty($post->post_type) || $post->post_type != 'attachment' ) 
  5. return $content; 
  6.  
  7. if ( wp_attachment_is( 'video', $post ) ) { 
  8. $atts = array( 'src' => wp_get_attachment_url() ); 
  9. if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { 
  10. $atts['width'] = (int) $meta['width']; 
  11. $atts['height'] = (int) $meta['height']; 
  12. if ( has_post_thumbnail() ) { 
  13. $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() ); 
  14. $p = wp_video_shortcode( $atts ); 
  15. } elseif ( wp_attachment_is( 'audio', $post ) ) { 
  16. $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) ); 
  17. } else { 
  18. $p = '<p class="attachment">'; 
  19. // show the medium sized image representation of the attachment if available, and link to the raw file 
  20. $p .= wp_get_attachment_link(0, 'medium', false); 
  21. $p .= '</p>'; 
  22.  
  23. /** 
  24. * Filters the attachment markup to be prepended to the post content. 
  25. * @since 2.0.0 
  26. * @see prepend_attachment() 
  27. * @param string $p The attachment HTML output. 
  28. */ 
  29.  
  30. return "$p\n$content";