Example 1 — Any Page
Add a class to every Page.
<?php if ( is_page() ) {
echo '<div class="page-wrap">';
} ?> How It Works
is_page()is true on every Page.- Blog posts are not Pages.
- The wrapper is printed only on Pages.

In WordPress, is_page() returns true when the visitor is viewing a Page, such as About or Contact. Blog posts are not Pages, so they return false.
Call it with no argument to match every Page. Pass an ID, a title, or a slug to match one Page.
Use it as the test of an if statement.
if ( is_page() ) {
// code for the true path
} else {
// code for the false path
} | Call | What it does |
|---|---|
is_page() | True on any Page. |
is_page( 'about' ) | True on the Page with the slug about. |
is_page( array( 42, 'contact' ) ) | True on the Page with ID 42 or the slug contact. |
For blog posts use is_single(). For both, use is_singular().
is_page( int|string|int[]|string[] $page = '' ): bool | Parameter | Description |
|---|---|
$page | Optional. A Page ID, title, slug, or an array of them. Default is empty, which means any Page. |
| Return Value | Description |
|---|---|
| bool | true if the main query is for a Page, otherwise false. |
Three short theme examples. Each one shows what prints on the true path and the false path.
Add a class to every Page.
<?php if ( is_page() ) {
echo '<div class="page-wrap">';
} ?> is_page() is true on every Page.Show a phone number on the Contact page.
<?php if ( is_page( 'contact' ) ) {
echo '<p>Call us: 555-0100</p>';
} ?> 'contact' is the Page slug.Use an array to match more than one Page.
<?php if ( is_page( array( 'about', 'team', 'careers' ) ) ) {
dynamic_sidebar( 'company-sidebar' );
} ?> Check if the current Page uses a custom page template.
15 people found this page helpful