Site logo

Archived topic

Template for attachments (image)

17 replies · Started by Alexander on August 23, 2019

Viewing posts 16–18 of 18

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 :)

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.

Looks good to me! :)

This archived topic is closed to new replies.