Created
October 26, 2023 12:05
-
-
Save humayunahmed8/cdd7117e591d9b3d602c20ce36bc495a to your computer and use it in GitHub Desktop.
Show slug based CPT single page from external directory
This file contains 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 | |
function custom_section_single_template($single) { | |
global $post; | |
if ($post->post_type == 'section' && is_single()) { | |
$slug = $post->post_name; | |
if ($slug === 'catalog') { | |
return get_template_directory() . '/section-templates-single/single-section-catalog.php'; | |
} elseif ($slug === 'banner') { | |
return get_template_directory() . '/section-templates-single/single-section-banner.php'; | |
} elseif ($slug === 'banner-five') { | |
return get_template_directory() . '/section-templates-single/single-section-banner-five.php'; | |
} | |
} | |
return $single; | |
} | |
add_filter('single_template', 'custom_section_single_template'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment