Created
September 22, 2016 10:19
-
-
Save mohammadmursaleen/d0eb556fbdfabd1f9991dc4f804af80a to your computer and use it in GitHub Desktop.
WordPress function to redirect to attachment url from attachment page url
This file contains hidden or 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 | |
/** | |
* @author Mohammad Murslaeen | |
* @function to redirect to attachment url from attachment page url | |
*/ | |
function mm_media_page_url_to_attachment_url(){ | |
if( 'attachment' != get_post_type( get_the_ID() ) ) | |
return; | |
wp_redirect( wp_get_attachment_url( get_the_ID() ) ); | |
exit; | |
} | |
add_action( 'template_redirect', 'mm_media_page_url_to_attachment_url' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment