Created
September 23, 2016 12:17
-
-
Save JeppeSigaard/bee0b6b87f0cf8e3a87aa770dd71dc28 to your computer and use it in GitHub Desktop.
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
<?php | |
/* | |
Plugin name: Attachment redirect | |
Description: Henvis sider for vedhæftning til forælder hvis den findes, eller forsiden hvis ikke. | |
Version: 0.1 | |
*/ | |
add_action('template_redirect', function(){ | |
global $post; | |
if(is_attachment()){ | |
if($post->post_parent){ | |
wp_redirect( get_permalink( $post->post_parent), 301); | |
} | |
else{ | |
wp_redirect(get_bloginfo('url'), 302); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment