is_sticky()WP 2.7.0

Checks if the current post is attached to the top of the home page posts query. Conditional tag.

Sticky posts is a posts that should remain at the top of The Loop.

See other conditional tags.

Hooks from the function

Return

true|false. Whether post is sticky.

Usage

<?php
if( is_sticky( $post_ID ) ){
	// ...
}
?>
$post_id(int)

The ID of the post you want to check whether it is attached to the main page.

If you don't specify this parameter, it will be the current post (in the loop or on the page).

Default: 0 - ID of the global $post

Examples

#1. Basic usage

if( is_sticky() ){
   // this is a sticky post
}

if( is_sticky( 17 ) ){
   // This will work if post with ID 17 is a sticky post.
}

Changelog

Since 2.7.0 Introduced.

Code of is_sticky() WP 6.0

function is_sticky( $post_id = 0 ) {
	$post_id = absint( $post_id );

	if ( ! $post_id ) {
		$post_id = get_the_ID();
	}

	$stickies = get_option( 'sticky_posts' );

	if ( is_array( $stickies ) ) {
		$stickies  = array_map( 'intval', $stickies );
		$is_sticky = in_array( $post_id, $stickies, true );
	} else {
		$is_sticky = false;
	}

	/**
	 * Filters whether a post is sticky.
	 *
	 * @since 5.3.0
	 *
	 * @param bool $is_sticky Whether a post is sticky.
	 * @param int  $post_id   Post ID.
	 */
	return apply_filters( 'is_sticky', $is_sticky, $post_id );
}