Question

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?

Was it helpful?

Solution

Try this:

basename(get_post_meta( $attachmentImage->ID, '_wp_attached_file', true));
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top