How Do I Add A Template To A Theme Using

[Solved] How Do I Add A Template To A Theme Using | Basic - Code Explorer | yomemimo.com
Question : How do I add a template to a theme using a plugin?

Answered by : imran-porda

<?php
//Add our custom template to the admin's templates dropdown
add_filter( 'theme_page_templates', 'pluginname_template_as_option', 10, 3 );
function pluginname_template_as_option( $page_templates, $theme, $post ){ $page_templates['template-landing.php'] = 'Example Landing Page'; return $page_templates;
}
//When our custom template has been chosen then display it for the page
add_filter( 'template_include', 'pluginname_load_template', 99 );
function pluginname_load_template( $template ) { global $post; $custom_template_slug = 'template-landing.php'; $page_template_slug = get_page_template_slug( $post->ID ); if( $page_template_slug == $custom_template_slug ){ return plugin_dir_path( __FILE__ ) . $custom_template_slug; } return $template;
}

Source : https://wordpress.stackexchange.com/questions/216376/how-do-i-add-a-template-to-a-theme-using-a-plugin | Last Update : Thu, 18 Aug 22

Answers related to how do i add a template to a theme using a plugin

Code Explorer Popular Question For Basic