برای اضافه کردن قالب برگه به جای اینکه در قالب اضافه کنیم می تونیم این کار رو در افزونه انجام بدیم . کافیه این کد رو به افزونه اضافه کنیم تا قالب برگه ما به لیست قالب برگه ها اضافه بشه
<?php
//Load template from specific page
add_filter( 'page_template', 'custom_page_template' );
function custom_page_template( $page_template ){
if ( get_page_template_slug() == 'custom_page_template.php' ) {
$page_template = dirname( __FILE__ ) . '/custom_page_template.php';
}
return $page_template;
}
/**
* Add "Custom" template to page attirbute template section.
*/
add_filter( 'theme_page_templates', 'add_custom_template_to_select', 10, 4 );
function add_custom_template_to_select( $post_templates, $wp_theme, $post, $post_type ) {
// Add custom template named template-custom.php to select dropdown
$post_templates['custom_page_template.php'] = 'custom page';
return $post_templates;
}