Title: why plugin
Last modified: August 20, 2016

---

# why plugin

 *  [zabatonni](https://wordpress.org/support/users/zabatonni/)
 * (@zabatonni)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/why-plugin/)
 * you can simply create file attachment.php inside your theme dir and paste this
   snippet there
 *     ```
       <?php
       $attached=$post->post_parent;
   
       if($attached==0) {
       wp_redirect(get_bloginfo('url'), 307);
       exit();
       }
       else {
       wp_redirect(get_permalink($clanok), 301);
       exit();
       }
       ?>
       ```
   
 * [http://wordpress.org/extend/plugins/attachment-pages-redirect/](http://wordpress.org/extend/plugins/attachment-pages-redirect/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Tecca](https://wordpress.org/support/users/tecca/)
 * (@tecca)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/why-plugin/#post-3191116)
 * That didn’t work on my end; it created a redirect that looped forever.
 * I used this:
 *     ```
       <?php
       header ('HTTP/1.1 301 Moved Permanently');
       header ('Location: '.get_permalink($post->post_parent));
       ?>
       ```
   
 *  Thread Starter [zabatonni](https://wordpress.org/support/users/zabatonni/)
 * (@zabatonni)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/why-plugin/#post-3191117)
 * sorry there was a mistake, try this:
 *     ```
       <?php
       $attached=$post->post_parent;
   
       if($attached==0) {
       wp_redirect(get_bloginfo('url'), 307);
       exit();
       }
       else {
       wp_redirect(get_permalink($attached), 301);
       exit();
       }
       ?>
       ```
   
 *  [Tecca](https://wordpress.org/support/users/tecca/)
 * (@tecca)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/why-plugin/#post-3191118)
 * That works perfectly. Thanks for that, zabatonni.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘why plugin’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/attachment-pages-redirect.svg)
 * [Attachment Pages Redirect](https://wordpress.org/plugins/attachment-pages-redirect/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/attachment-pages-redirect/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/attachment-pages-redirect/)
 * [Active Topics](https://wordpress.org/support/plugin/attachment-pages-redirect/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/attachment-pages-redirect/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/attachment-pages-redirect/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Tecca](https://wordpress.org/support/users/tecca/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/why-plugin/#post-3191118)
 * Status: not a support question