Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

http://domain.com/groups/group-name/docs/doc-name/attachment-name

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

http://domain.com/?attachment_id=123

Thanks!

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.