| 1 |
<?php |
| 2 |
//Add our custom template to the admin's templates dropdown |
| 3 |
add_filter( 'theme_page_templates', 'pluginname_template_as_option', 10, 3 ); |
| 4 |
function pluginname_template_as_option( $page_templates, $theme, $post ){ |
| 5 |
|
| 6 |
$page_templates['canvas.php'] = 'Blockspare Canvas'; |
| 7 |
$page_templates['full-width.php'] = 'Blockspare Full-Width'; |
| 8 |
|
| 9 |
return $page_templates; |
| 10 |
|
| 11 |
} |
| 12 |
|
| 13 |
//When our custom template has been chosen then display it for the page |
| 14 |
add_filter( 'template_include', 'pluginname_load_template', 99 ); |
| 15 |
function pluginname_load_template( $template ) { |
| 16 |
|
| 17 |
global $post; |
| 18 |
$canvas_template_slug = 'canvas.php'; |
| 19 |
$full_width_template_slug = 'full-width.php'; |
| 20 |
$page_template_slug = get_page_template_slug( $post->ID ); |
| 21 |
|
| 22 |
if( $page_template_slug == $canvas_template_slug ){ |
| 23 |
return BLOCKSPARE_PLUGIN_DIR . 'inc/page-templates/templates/' . $canvas_template_slug; |
| 24 |
} |
| 25 |
|
| 26 |
if( $page_template_slug == $full_width_template_slug ){ |
| 27 |
return BLOCKSPARE_PLUGIN_DIR . 'inc/page-templates/templates/' . $full_width_template_slug; |
| 28 |
} |
| 29 |
|
| 30 |
return $template; |
| 31 |
|
| 32 |
} |