Skip to content

Instantly share code, notes, and snippets.

@mrfoxtalbot
Forked from braddalton/functions.php
Last active September 30, 2016 17:34
Show Gist options
  • Save mrfoxtalbot/cedb029ba6fa2d4d48e62d06fa5cf8d1 to your computer and use it in GitHub Desktop.
Save mrfoxtalbot/cedb029ba6fa2d4d48e62d06fa5cf8d1 to your computer and use it in GitHub Desktop.
Redireccionar adjuntos al post asociado
add_action( 'template_redirect', 'wpsites_attachment_redirect' );
function wpsites_attachment_redirect(){
global $post;
if ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0) ) :
wp_redirect( get_permalink( $post->post_parent ), 301 );
exit();
wp_reset_postdata();
endif;
}
// fuente: http://wpsites.net/wordpress-tips/5-ways-to-redirect-attachment-pages-to-the-parent-post-url/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment