谢谢大家的建议!我想在post only上默认设置“Elementor canvas”模板,我这样做了:
function default_post_template_elementor_canvas($post_type, $post)
{
$wishedTemplate = \'elementor_canvas\'; // to see available template var_dump(get_page_templates($post))
if ($post_type === \'post\'
&& in_array($wishedTemplate, get_page_templates($post)) // Only if elementor_canvas is available
&& $post->ID != get_option(\'page_for_posts\') // Not the page for listing posts
&& metadata_exists(\'post\', $post->ID, \'_wp_page_template\') === false) { // Only when meta _wp_page_template is not set
add_post_meta($post->ID, \'_wp_page_template\', $wishedTemplate);
}
}
add_action(\'add_meta_boxes\', \'default_post_template_elementor_canvas\', 10, 2);