您能在template_include
滤器否则,您可以设置全局/常量并在template_include
提供适当的模板。
template\\u include筛选器文件管理要包含的模板文件的路径。为了避免错误,您应该检查模板是否存在-locate\\u template对主题/子主题文件执行此操作。
add_filter("template_include", "sc_redirect_properties_to_registration");
function sc_redirect_properties_to_registration( $template )
{
if( is_user_logged_in() && ! is_page("the-properties") )
return $template;
//You could include templates from plugins
//$template = plugin_dir_path(__FILE__).\'templates/plugin-template.php\';
//Best to check the template exists. With **theme/child-theme** templates
// you can do this with locate_template.
return locate_template(\'template-registration.php\');
}