Skip to content

Instantly share code, notes, and snippets.

@humayunahmed8
Created October 26, 2023 12:05
Show Gist options
  • Save humayunahmed8/cdd7117e591d9b3d602c20ce36bc495a to your computer and use it in GitHub Desktop.
Save humayunahmed8/cdd7117e591d9b3d602c20ce36bc495a to your computer and use it in GitHub Desktop.
Show slug based CPT single page from external directory
<?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