Discover, trust, install: FAIR 1.0 is here

Plugin Banner

Attachment Pages Redirect

by Samuel Aguilera

Version: 1.1.2

Download
Description

There are three possible scenarios where this plugin does something. In all cases, the attachment page must exists, the plugin will not run for deleted attachments:

A) A visitor lands on an attachment page and the parent post is available (not in trash or deleted). A 301 redirect will be issued to redirect the visitor to the parent post.

B) A visitor lands on an attachment page and the parent post was already deleted from trash. A 302 redirect is issued to home page (this can be changed to 301 if you want, see FAQ for more details).

C) A visitor lands on an attachment page and the parent post is in trash, therefore not available for the visitor. It returns a 404 error code to prevent endless redirection loop in old WP releases and redirecting to trashed/not available posts.

There is no options page, simply activate it and will do the job.

If you’re happy with the plugin please don’t forget to give it a good rating, it will motivate me to keep sharing and improving this plugin (and others).

Requirements

  • WordPress 4.8 or higher.
  • Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation (or install it directly from your dashboard) and then activate the Plugin from Plugins page.
WordPress is returning a 404 error for my attachment pages, will this plugin help?

No. This plugin needs an existing attachment to work, if you deleted the attachment WordPress will return a 404 for its attachment page and this plugin doesn’t support that scenario.

Can I change the HTTP codes used for the redirections?

Since version 1.1 you can do this by adding constants to your wp-config.php file. The example below will switch the redirection codes used by default.

define( 'ATTACHMENT_REDIRECT_CODE', '302' );
define( 'ORPHAN_ATTACHMENT_REDIRECT_CODE', '301' );

Use this at your own risk, only if you know what you’re doing!! No support will be offered for this.

Great!

By sailboats25 on June 20, 2024

This plugin has been such a big help for my website. Before, people clicking an image they found in Google Images would be taken to the image's attachment page with no other context. Now they are taken to the page we want them to go to, leading to better engagement with our site.

Perfect

By robegb on April 22, 2023

Exactly what I needed. Thanks!

Works immediately

By Joey (joey4j) on January 11, 2023

I didn't want any attachment pages to be accessed by visitors, then found this plugin that does the job by just installing and activating. Thanks!

Sorry this is not working anymore

By metaeditor on December 3, 2022

Plugin is not working anymore

The Best only.

By dikasparaandroid on March 13, 2022

thanks man. You save a bigger work here. Thanks for this.

It just works

By jplew on September 20, 2021

Works perfectly with no config needed. Doesn't get better than this folks.

Brilliant

By Twinky9 on July 24, 2021

The problem was driving me crazy. Thankyou!

Super Helpful! Thank You Samuel

By masudsuhail on May 16, 2021

This plugin is super fast and worked like Wow for me!

Perfect !

By cheesemaker67 on July 7, 2020

Simple installation, worked first time. Thank you Samuel !

Just best!

By feeel on February 4, 2020

It really helped me! Thank you!

1.1.2

  • Changed code for 404 scenario to use the theme’s 404 template if it’s available.

1.1.1

  • Minor changes to make code 100% compliant with WordPress Coding Standards. This doesn’t means any change in the plugin functionality, it’s just code cosmetic.

1.1

  • Minor coding standards improvements.
  • Added ATTACHMENT_REDIRECT_CODE and ORPHAN_ATTACHMENT_REDIRECT_CODE constants to allow change the HTTP redirection codes (e.g. change 302 to 301 for orphan attachments)
  • Prevent endless redirection loop in old WP releases and redirecting to trashed/not available posts if an attachment page is visited when parent post is in trash. Returning a 404 error in this case.

1.0

  • Initial release.
  • Version:Version: 1.1.2
  • Active installs:Active installs: 20K
  • Last updated:Last updated: 05-10-2023
  • Requires:Requires: 4.8
  • Tested:Tested: 6.3.5
Average rating:4.9 out of 5 stars.
  • Number of ratings: 45 ratings
  • Number of ratings: 1 ratings
  • Number of ratings: 0 ratings
  • Number of ratings: 0 ratings
  • Number of ratings: 1 ratings
Back to top