Code Element Tr
Redirect to Custom WordPress Template
You can redirect multiple WordPress post types to the same template using the native template_redirect action hook and template_include filter hook.
Replace:
post-type-one and post-type-two: with your post types
path/to/new/template.php: with your template path
/**
* Custom Template Redirects
*/
add_action('template_redirect', function () {
// Redirect two Post Type Archives to the same template
if (is_post_type_archive('post-type-one') || is_post_type_archive('post-type-two')) {
$template = get_template_directory() . '/path/to/new/template.php';
if (file_exists($template)) {
add_filter('template_include', function() use ($template) {
return $template;
});
}
}
});