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 have buddypress installed. All URL goes under BP's URL structure. If an attachment belongs to a document in a group, the URL is:


I would like to learn how to change the attachment URL to:



share|improve this question
up vote 2 down vote accepted

The attachment URL is created in wp-includes/link-template.php in function get_attachment_link(). And there is a filter for you, passing the WordPress URL and the post id for the attachment. You can hook into that filter and return the URL you need:

add_filter( 'attachment_link', 'wpse_56619_unprettify_attachment_url', 10, 2 );

function wpse_56619_unprettify_attachment_url( $link, $id )
    return home_url( "/?attachment_id=$id" );
share|improve this answer
Thanks! It works! After add the filter, what to do if I want to change /?attachment_id= to /?presentation= – Jenny Sep 1 '12 at 9:25
Almost impossible. That string is hard coded all over the place in core. It is also used in POST requests, so a simple rewrite rule will not do it. – toscho Sep 1 '12 at 9:29
Thanks for making this crystal clear! I've tried all tips I found on the net. – Jenny Sep 1 '12 at 11:22

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.