WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm doing up a photography site where each post is a photo project, and each post attachment will be displayed on its own attachment page (linked to from the main post page).

On the attachment page, I want to give an email link, below the image.

At the moment, the code is something like this:

<a href="mailto:me@whatever.com?Subject=Image: <?php the_title(); ?> - [FILE NAME HERE]">Get in touch about this image</a>

I want the subject of the email to include the file name of the attachment (not title, not meta info, not attachment page URL). Is this possible? If so, how would I do it?


share|improve this question
up vote 0 down vote accepted

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="mailto:me@whatever.com?Subject=Image: <?php the_title(); ?> - <?php echo basename( wp_get_attachment_url( $post->ID ) ); ?>">Get in touch about this image</a>
share|improve this answer
Thanks! Is there any easy way to get rid of the '.jpg' at the end of the file name? – kopfschmerz Mar 20 '13 at 1:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.