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?

1 Answer 1


Try this:

basename(get_post_meta( $attachmentImage->ID, '_wp_attached_file', true));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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