is_page_template()
最后更新于:2021-11-27 09:43:21
is_page_template( string|string[]$template=”)Determines whether currently in a page template.
参数
- $template
-
(string|string[]) (Optional) The specific template filename or array of templates to match.
Default value: ”
响应
(bool) True on success, false on failure.
源文件
文件: gc-includes/post-template.php
function is_page_template( $template = '' ) {
if ( ! is_singular() ) {
return false;
}
$page_template = get_page_template_slug( get_queried_object_id() );
if ( empty( $template ) ) {
return (bool) $page_template;
}
if ( $template == $page_template ) {
return true;
}
if ( is_array( $template ) ) {
if ( ( in_array( 'default', $template, true ) && ! $page_template )
|| in_array( $page_template, $template, true )
) {
return true;
}
}
return ( 'default' === $template && ! $page_template );
}