Created
August 7, 2019 06:04
-
-
Save hmbashar/c6d23f1c7b44edfe275b4c2fcf849837 to your computer and use it in GitHub Desktop.
plugin_tamplate_add_page_attribute_dropdown
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 | |
function plugin_tamplate_add_page_attribute_dropdown( $post_templates, $wp_theme, $post, $post_type ) { | |
$post_templates['pagetamplate.php'] = __('My Plugin Tamplate'); | |
return $post_templates; | |
} | |
add_filter( 'theme_page_templates', 'plugin_tamplate_add_page_attribute_dropdown', 10, 4 ); | |
function load_tamplate_from_plugin( $template ) { | |
if( get_page_template_slug() === 'pagetamplate.php' ) { | |
if ( $theme_file = locate_template( array( 'pagetamplate.php' ) ) ) { | |
$template = $theme_file; | |
} else { | |
$template = plugin_dir_path( __FILE__ ) . 'pagetamplate.php'; | |
} | |
} | |
if($template == '') { | |
throw new \Exception('No template found'); | |
} | |
return $template; | |
} | |
add_filter( 'template_include', 'load_tamplate_from_plugin' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment