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.

In wordpress, an unattached attachment URL is

http://domain.com/?attachment=$id

Once after it's attached to a parent, it goes with parent's URL structure, for example:

http://domain.com/parent-title/attachment-title

I need my attachments URL contains only root domain as the unattached ones. How to make it?

share|improve this question
    
Just out of curiosity, why? –  jprofitt Aug 5 '12 at 13:40
add comment

migrated from stackoverflow.com Aug 5 '12 at 15:12

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 0 down vote accepted

You can add a filter to the function that gets attachment links to force that format:

function wpa60888_attachment_link( $link, $id ){
    return home_url() . '/?attachment_id=' . $id;
}
add_filter( 'attachment_link', 'wpa60888_attachment_link', 10, 2 );

Calls to get_attachment_link will have this filter applied to the output.

share|improve this answer
    
This filter works only if site is under default permalink structure. If site use pretty permalink structure, it will go with the pretty ones. –  Jenny Aug 5 '12 at 21:35
    
Just figure out where I went wrong-- the file I add the above function was required if is_admin. Now I have the file loaded disregarding admin or not, the filter works. Thanks! –  Jenny Aug 5 '12 at 22:04
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.