Last active
June 4, 2019 09:45
-
-
Save thisolivier/1365e954bdf6a64c2d336f2bd2828081 to your computer and use it in GitHub Desktop.
Wordpress - No more media attachment or author pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Redirect away from attachment and author pages | |
* Add this snippet to your functions or filters php files, as appropriate (if in doubt, the bottom of functions.php will do) | |
* Feel free to message thisOlivier on github/stackOverflow if you get stuck | |
* | |
*/ | |
add_action('template_redirect', function() { | |
if (is_attachment() || is_author()) { | |
global $post; | |
if ($post && $post->post_parent) { | |
wp_redirect(esc_url(get_permalink($post->post_parent)), 301); | |
return; | |
} else { | |
wp_redirect(esc_url(home_url('/')), 301); | |
return; | |
} | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment