Last active
May 3, 2021 07:38
-
-
Save andrii-kvlnko/77e96072b7cef7c56f4902e0c41267ee to your computer and use it in GitHub Desktop.
WordPress - Template redirect
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
function prefix_url_rewrite_templates() { | |
if ( get_query_var( 'photos' ) && is_singular( 'news' ) ) { | |
add_filter( 'template_include', function() { | |
return get_template_directory() . '/single-news-image.php'; | |
}); | |
} | |
if ( get_query_var( 'videos' ) && is_singular( 'news' ) ) { | |
add_filter( 'template_include', function() { | |
return get_template_directory() . '/single-news-video.php'; | |
}); | |
} | |
} | |
add_action( 'template_redirect', 'prefix_url_rewrite_templates' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment