1

I've just started using the attachment.php template on my site. What I'd like to do is redirect all images in posts that used 'file url' to 'post url' and my new attachment.php template.

Is this possible?

Thanks in advance for any help.

EB

2
  • It might help to provide your code for the attachment.php. Commented Aug 8, 2011 at 22:34
  • For clarity(as i think i follow the question), Everton is asking how he can update all posts that currently reference an attach in their content and point to the file url, and replace those URLs with the individual attachments URL. Something you'll likely only get done with custom SQL and regex...(there's no quick one liner for this)..
    – t31os
    Commented Aug 9, 2011 at 0:11

2 Answers 2

1

Link to the image file using wp_get_attachment_link( $id, $size, $permalink, $icon, $text ):

  • $id is the attachment ID, which, if using attachment.php, will simply be $post->ID
  • $size is the image size, e.g. full, large, medium, thumbnail
  • $permalink determines whether a link to the file or post is returned. Use false (which is the default) to link to the file
  • $icon refers to a mime-type icon. Leave false, which is default
  • $text displays a text link. Leave false, which is default
2
  • thanks for the answer. How and where do I add this code so that old posts linking to images via the file url, will 'redirect' to the post url for the image? Commented Aug 10, 2011 at 9:16
  • It would go in the Loop, and replace the current code, which, I'm guessing is simply the_content(), in attachment.php Commented Aug 10, 2011 at 11:44
0

Take a look at the solution on the WordPress Support Forum: http://wordpress.org/support/topic/redirect-attachment-page-to-post-page-how-to

1
  • Thanks, but this goes the wrong way around - post url 2 file url, not file url 2 post url Commented Aug 10, 2011 at 9:17

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.