is_page_template()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
is_page_template( string|string[] $template = '' ): bool
Описание
Этот тег шаблона позволяет определить, находитесь ли вы в шаблоне страницы.
При желании можно указать имя файла шаблона или массив имён файлов шаблонов, тогда проверка будет относиться именно к этому шаблону.
Подробнее об этой и похожих функциях темы смотрите в статье Conditional Tags в Theme Developer Handbook.
Оригинал (английский)
This template tag allows you to determine if you are in a page template.
You can optionally provide a template filename or array of template filenames and then the check will be specific to that template.
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Параметры
$template
string|string[]
необязательный
= ''
Возвращаемое значение
bool
Исходный код
wp-includes/post-template.php:1854
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 );
}
История изменений
| Версия | Описание |
|---|---|
| 4.7.0 | Now works with any post type, not just pages. |
| 4.2.0 | The $template parameter was changed to also accept an array of page templates. |
| 2.5.0 | Introduced. |

