Attachment Pages Redirect - Version 1.0

Version Description

  • Initial release.
Download this release

Release Info

Developer samuelaguilera
Plugin Icon wp plugin Attachment Pages Redirect
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (2) hide show
  1. attachment-pages-redirect.php +38 -0
  2. readme.txt +38 -0
attachment-pages-redirect.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Attachment Pages Redirect
4
+ Plugin URI:
5
+ Description: Makes attachment pages redirects (301) to post parent if any. If not, redirects (302) to home page.
6
+ Author: Samuel Aguilera
7
+ Version: 1.0
8
+ Author URI: http://www.samuelaguilera.com
9
+ */
10
+
11
+ /*
12
+ This program is free software: you can redistribute it and/or modify
13
+ it under the terms of the GNU General Public License version 3 as published by
14
+ the Free Software Foundation.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ */
24
+
25
+ function sar_attachment_redirect() {
26
+ global $post;
27
+ if ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0) ) {
28
+ wp_redirect(get_permalink($post->post_parent), 301); // permanent redirect to post/page where image or document was uploaded
29
+ exit;
30
+ } elseif ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent < 1) ) { // for some reason it doesnt works checking for 0, so checking lower than 1 instead...
31
+ wp_redirect(get_bloginfo('wpurl'), 302); // temp redirect to home for image or document not associated to any post/page
32
+ exit;
33
+ }
34
+ }
35
+
36
+ add_action('template_redirect', 'sar_attachment_redirect',1);
37
+
38
+ ?>
readme.txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Attachment Pages Redirect ===
2
+ Contributors: samuelaguilera
3
+ Tags: attachment, redirect, images
4
+ Requires at least: 3.3
5
+ Tested up to: 4.7.2
6
+ Stable tag: 1.0
7
+ License: GPLv2
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Makes attachment pages redirects (301 permanent redirect) to post parent if any. If not, redirects (302 temporal redirect) to home page.
11
+
12
+ == Description ==
13
+
14
+ Makes attachment pages redirects (301 permanent redirect) to post parent if any. If not, redirects (302 temporal redirect) to home page.
15
+
16
+ There is no option page, simply activate it and will do the job.
17
+
18
+ Please, if you like this plugin. Rate it ;)
19
+
20
+ = Requirements =
21
+
22
+ * WordPress 3.3 or higher.
23
+
24
+ == Installation ==
25
+
26
+ * Extract the zip file and just drop the contents in the <code>wp-content/plugins/</code> directory of your WordPress installation (or install it directly from your dashboard) and then activate the Plugin from Plugins page.
27
+
28
+ == Frequently Asked Questions ==
29
+
30
+ = Will this plugin works in WordPress older than 3.3? =
31
+
32
+ Maybe, but not tested and not supported. Just try yourself.
33
+
34
+ == Changelog ==
35
+
36
+ = 1.0 =
37
+
38
+ * Initial release.