How to Check if a Post is Sticky in WordPress (+Example)

1.6666666666667 from 5
from 6 user
(Rate this post)
How to Check if a Post is Sticky in WordPress (+Example)

Sticky posts in WordPress will stick to the top of the post lists. Moderators can set a post to be sticky inside the WordPress admin panel. Developers can check if a post is sticky or not in WordPress, using the is_sticky function. In this WordPress tutorial, We're going to set a sticky post and check if the is_sticky function detects it as a sticky post or not.

How to check if a specific post is sticky when developing WordPress?

is_sticky function will help you in this situation.

Just give the is_sticky function a post ID , and it will determine if a post is sticky or not with a true/false value.

The current queried post will be targeted if you do not specify a post ID.

is_sticky function syntax

The syntax is pretty easy and understandable:

is_sticky(int $postId)

is_sticky function example

To check if the post with ID 1 is sticky or not in WordPress, you can use this code:

$postId = 1;
if(is_sticky(int $postId)){
    //post is sticky!

}

What do you think about "How to Check if a Post is Sticky in WordPress (+Example)"?

Your rating submit was successfull.

Your rating submit was not successfull.

Menu