我们可以利用page_template
过滤以实现此目的。我们需要做的就是确保confirmation
是页面标题中的第一个单词
add_filter( \'page_template\', function ( $template )
{
// Get the current page object
$post = get_queried_object();
/**
* Get the first instance of confirmation, if it is not 0, bail
* We will be using the page name, which is the slug
*/
if ( 0 !== stripos( $post->post_name, \'confirmation\' ) )
return $template;
// We have confimation as first word, lets continue
$locate_template = locate_template( \'page-confirmation.php\' );
// Check if $locate_template is not empty, if so, bail
if ( !$locate_template )
return $template;
// page-confirmation.php exist, return it
return $locate_template;
});