I'm having issues getting some custom meta boxes to display on the page default template. I want these meta boxes to only display on the default template and disappear when the user chooses a different page template. Below is the code I have tried.
add_action( 'add_meta_boxes', 'add_page_meta' );
function add_page_meta() {
global $post;
if(!empty($post)) {
$pageTemplate = get_post_meta($post->ID, '_wp_page_template', true);
if( $pageTemplate == 'page-templates/page.php') {
add_meta_box('banner-attributes', 'Banner Attributes', 'banner_attributes_callback', 'page', 'side');
echo("<script>console.log('true');</script>");
}
}
}
I also noticed when changing the if condition from 'page-templates/page.php' to 'page-templates/page-notitle.php' the function would work as intended. I have both a page.php and a page-notitle.php within my page-templates folder. Do I need to reference the default template as something other than page.php?
Thanks!