It’s certainly possible. Here’s an example:
// add the new template to the dropdown
add_filter( 'theme_page_templates', function ( $templates ) {
$templates['advanced-course-filter.php'] = __( 'Advanced Course Filter' );
} );
// load the template when viewing the page
add_filter( 'page_template', function ( $template ) {
if ( get_page_template_slug() === 'advanced-course-filter.php' ) {
$template = WP_CONTENT_DIR . '/advanced-course-filter.php';
}
return $template;
} );
The only things you should need to change here are:
'Advanced Course Filter' to whatever you want the name of the template to be in the WordPress dropdown list.
advanced-course-filter.php to the filename of the page template file.
WP_CONTENT_DIR to the filesystem location of where you’ve stored the page template file.
Hopefully this is what you’re looking for!
great to hear that this is possible. But will it load all resources on all pages or only on the page i specify?
so it will not be overwritten after theme update?
1.’Advanced Course Filter’ to whatever you want the name of the template to be in the WordPress dropdown list.
With WordPress dropdown list you mean when i assign template to the page correct?
So i can leave it as same name.
2. advanced-course-filter.php to the filename of the page template file.
If i use the same php file then wouldn’t it be overwritten after next theme update?
please explain this part.
3. WP_CONTENT_DIR to the filesystem location of where you’ve stored the page template file.
What would be a good place to place the page template file in without being overwritten after update.
Sorry for all the questions but i allready got my fingers burned by losing a complete customized page because of the overwriting part.
Thank you for your reply, I appreciate it
If you make a file called advanced-course-filter.php and put it directly in your site’s wp-content directory, then you should be able to use the code I posted unchanged.