[Resolved] Template for attachments (image)

Home Forums Support [Resolved] Template for attachments (image)

Home Forums Support Template for attachments (image)

  • This topic has 17 replies, 3 voices, and was last updated 2 years ago by Tom.
Viewing 3 posts - 16 through 18 (of 18 total)
  • Author
    Posts
  • #996829
    Tom
    Lead Developer
    Lead Developer

    You could try this, instead:

    add_filter( 'prepend_attachment', function( $attachment_content ) {
            global $post;
    
            $excerpt = '<div class="attachment-excerpt">' . $post->post_excerpt . '</div>';
    
            // set the attachment image size to 'large'
            $attachment_content = sprintf( '<p>%s</p>', wp_get_attachment_link(0, 'large', false) );
            
            // return the attachment content
            return $attachment_content . $excerpt;
            
    } );

    Let me know πŸ™‚

    #996857
    Alexander

    I’ll never be able to wrap my old head around this syntax but it works. THANKS!

    I fine-tuned it into this with plenty of trial and error, I hope this gets your approval. πŸ™‚

    add_filter( 'prepend_attachment', function( $attachment_content ) {
            global $post;
    
            // get the attachment caption
      		$excerpt = '<figcaption class="wp-caption-text">' . $post->post_excerpt . '</figcaption></figure>';
    
            // set the attachment image size to 'large'
            $attachment_content = sprintf( '<figure class="wp-caption">%s', wp_get_attachment_link(0, 'large', false) );
      		   
            // return the attachment content
            return $attachment_content . $excerpt;
    } );

    Final result: https://www.alex-kunz.com/portfolio/tabletop-tide-pools/filaments-of-green/#main

    Thanks again, your help is very much appreciated.
    Alexander.

    #997327
    Tom
    Lead Developer
    Lead Developer
Viewing 3 posts - 16 through 18 (of 18 total)
  • You must be logged in to reply to this topic.