0

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.

0

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>
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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