Adding attachment file name to email link

You can get the original attachment filename via wp_get_attachment_url:

echo basename( wp_get_attachment_url( $post->ID ) );

or in the form of the example you provided:

<a href="https://wordpress.stackexchange.com/questions/91547/mailto:[email protected]?Subject=Image: <?php the_title(); ?> - <?php echo basename( wp_get_attachment_url( $post->ID ) ); ?>">Get in touch about this image</a>

Leave a Comment