Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks.

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.