So I've got a bunch of content with images inserted into them. The users inserting content have done the default option of linking to the attachment page which isn't great. I've altered the

setting to make this link to the file by default now.

But I'd like to use a light box or something to display images on the site, which requires the to go to the image file, not the attachment page. Whilst I can make this work for images added since the default was changed, I was wondering if there was any solution that could make this change for me that was not going through and altering the content of each post?

TIA, Dan.

1 Answer 1


If you are never going to use the attachment page, then you can simply change the HTTP header ( a php function ) of attachment page to the image file.

Example -

header('Location: ' . wp_get_attachment_url() );

Note - Call it inside WordPress loop.

  • It's that simple :O
    – gravy
    Commented Aug 21, 2012 at 21:10
  • Just a thought, should work.
    – Amit Kosti
    Commented Aug 21, 2012 at 21:23
  • 1
    Because this will not alter the links on the page, it's more of an hack (a nice one) and not a real solution because it doesn't change the links on the page. Links will still go to the attachment page. In some scenarios it would be better to change the links on the page. e.g. if you want to run Lightbox / Colorbox to preview images.
    – grm
    Commented Feb 10, 2013 at 3:49

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.