WordPress is_sticky() Function

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

Definition

In WordPress, is_sticky() returns true when a post is marked as sticky. A sticky post stays at the top of the blog posts index.

With no argument it checks the current post in The Loop. You can also pass a post ID to check any post.

Syntax

Use it as the test of an if statement.

WordPress
if ( is_sticky() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_sticky()True if the current post is sticky.
is_sticky( 42 )True if the post with ID 42 is sticky.
! is_sticky()True for a normal post.

To make a post sticky, tick "Stick to the top of the blog" in the editor.

Full declaration
WordPress
is_sticky( int $post_id = 0 ): bool

Parameters

ParameterDescription
$post_idOptional. The post ID. Default is 0, which means the current post.

Return Value

Return ValueDescription
booltrue if the post is sticky, otherwise false.

WordPress Examples

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

Example 1 — Add a Featured label

Mark sticky posts in the loop.

WordPress
<?php if ( is_sticky() ) : ?>
  <span class="badge">Featured</span>
<?php endif; ?>
<h2><?php the_title(); ?></h2>

How It Works

  1. is_sticky() checks the current post in the loop.
  2. The badge is printed only for sticky posts.
  3. The title is printed for every post.

Example 2 — Check a post ID

Test a post outside the loop.

WordPress
<?php echo is_sticky( 42 ) ? 'Post 42 is sticky' : 'Post 42 is not sticky'; ?>

How It Works

  1. The argument 42 is a post ID.
  2. The short ? : form prints one of two texts.
  3. No loop is needed when you pass an ID.

Example 3 — Add a CSS class

Style sticky posts in your CSS.

WordPress
<?php $class = is_sticky() ? 'post sticky-post' : 'post'; ?>
<article class="<?php echo esc_attr( $class ); ?>">

How It Works

  1. The class name depends on the result.
  2. esc_attr() makes it safe.
  3. WordPress already adds a sticky class with post_class(), but this shows the idea.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
Sticky posts appear at the top of the first page of the blog posts index.
No. Sticky is a feature of blog posts.
Only if you leave out the post ID. With an ID it works anywhere.

Next: is_super_admin()

Check if a user is a Super Admin (network administrator).

is_super_admin() 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.

15 people found this page helpful