Skip to content

Instantly share code, notes, and snippets.

@thisolivier thisolivier/functions.php
Last active Jun 4, 2019

What would you like to do?
Wordpress - No more media attachment or author pages
* 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);
} else {
wp_redirect(esc_url(home_url('/')), 301);
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.