Skip to content

Instantly share code, notes, and snippets.

@JeppeSigaard
Created September 23, 2016 12:17
Show Gist options
  • Save JeppeSigaard/bee0b6b87f0cf8e3a87aa770dd71dc28 to your computer and use it in GitHub Desktop.
Save JeppeSigaard/bee0b6b87f0cf8e3a87aa770dd71dc28 to your computer and use it in GitHub Desktop.
<?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