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 using a function to display all files attached to a post and listing them as links. The result is something like this:

echo '<a href="' . wp_get_attachment_url($attachmentImage->ID) . 
          '" class="dir-attachment" />' . wp_get_attachment_url($attachmentImage->ID) . '</a>';

As expected, this display a hyperlinked version of the hyperlink, but I'd like to clean it up. Is there some way to strip the http://mydomain/wp-content/uploads from the second instance display the file name only, rather than the full path?

share|improve this question
up vote 4 down vote accepted

Try this:

basename(get_post_meta( $attachmentImage->ID, '_wp_attached_file', true));
share|improve this answer
Perfect. Thanks! – John Chandler Jan 14 '11 at 19:40

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.