Skip to content

Instantly share code, notes, and snippets.

@IkeTen
Forked from ollietreend/image.php
Created December 7, 2016 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IkeTen/af32852e75e2c60611eb622acbca0eac to your computer and use it in GitHub Desktop.
Save IkeTen/af32852e75e2c60611eb622acbca0eac to your computer and use it in GitHub Desktop.
Disable WordPress media attachment page by redirecting to the parent post. Original idea from: http://www.wpbeginner.com/wp-tutorials/how-to-disable-image-attachment-pages-in-wordpress/
<?php
/**
* Disables the media attachment page by redirecting the user elsewhere.
* Save as 'image.php' in theme.
* Inspired by http://www.wpbeginner.com/wp-tutorials/how-to-disable-image-attachment-pages-in-wordpress/
*/
if ($post->post_parent) {
wp_redirect(get_permalink($post->post_parent), 301);
} else {
wp_redirect(site_url(), 301);
}
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment