function custom_page_template( $templates ) {
$templates[‘home-page.php’] = ‘Home page’;
return $templates;
}
add_filter( ‘theme_page_templates’, ‘custom_page_template’ );
This code adds a custom page template with the name “Home page” and the file “home-page.php“. The “custom_page_template” function defines a new template and adds it to the templates array. The “add_filter” function then adds this template to the WordPress theme’s list of page templates.
Steps:
1. The “custom_page_template” function creates a new page template with the name “Home page” and the file “home-page.php“.
2. The template is added to the array of templates using the “home-page.php” key.
3. The function returns the updated array of templates.
4. The “add_filter” function adds this template to the list of WordPress theme page templates.