WordPress is_preview() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress, is_preview() returns true when an author is previewing a post or page, for example after clicking Preview in the editor, before it is published.

Use it to show a "preview" notice, or to hide things that should only run for real visitors, such as analytics.

Syntax

Use it as the test of an if statement.

WordPress
if ( is_preview() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_preview()True when the post is in preview mode.
! is_preview()True for normal visitors.
is_customize_preview()A different tag for the Customizer preview.

Only a logged-in user who can edit the post can open a preview.

Full declaration
WordPress
is_preview(): bool

Parameters

ParameterDescription
NoneThis function takes no parameters.

Return Value

Return ValueDescription
booltrue if the main query is a preview, otherwise false.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Show a preview notice

Remind the author that this page is not live yet.

WordPress
<?php if ( is_preview() ) {
  echo '<p class="notice">Preview mode. This post is not public.</p>';
} ?>

How It Works

  1. is_preview() is true only in preview mode.
  2. The notice is printed above the post.
  3. Visitors never see it.

Example 2 — Skip analytics in preview

Do not count editor previews as visits.

WordPress
<?php if ( ! is_preview() ) {
  echo '<script src="/analytics.js"></script>';
} ?>

How It Works

  1. ! is_preview() means this is not a preview.
  2. The script is printed only for real visits.
  3. Your numbers stay clean.

Example 3 — Preview only on single posts

Combine with is_single().

WordPress
<?php if ( is_single() && is_preview() ) {
  echo 'Previewing a post';
} ?>

How It Works

  1. is_single() checks for a single post.
  2. is_preview() checks for preview mode.
  3. Both must be true.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
Only users who can edit that post, for example the author or an editor.
No. Use is_customize_preview() for the Customizer.
Yes. It is true when you preview a Page too.
Conditional tags need the main query. Call them in template files or on hooks such as wp or template_redirect, not directly at the top of functions.php.

Next: is_privacy_policy()

Check if the current page is the Privacy Policy page.

is_privacy_policy() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful