Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
25 Million+
Websites using our plugins
Years of WordPress experience
WordPress tutorials
by experts

How to Exclude Sticky Posts from the Loop in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you want to exclude a sticky post from the loop in WordPress?

Sticky posts are a great way to highlight your featured content. However, there are certain places on your website where you don’t need sticky posts to be on the top.

In this article, we will show you how to completely exclude sticky posts from the loop in WordPress.

How to exclude sticky posts from the loop in WordPress

Why Should You Exclude Sticky Posts from the Loop?

Removing sticky posts from a loop on your WordPress website can be helpful if you don’t want to show them in a particular area on your WordPress website.

Sticky posts are useful in highlighting important content like your pillar articles, high-traffic blog posts, and time-sensitive content. However, they can crowd your most recent posts widget area and make your latest content harder to access.

This is where excluding sticky posts from the loop comes in handy. WordPress can not guess this so you need to explicitly tell WordPress to exclude sticky blog posts from a custom loop.

Let’s see how you can remove sticky posts from the loop in WordPress.

Excluding Sticky Posts from the Loop in WordPress

To help you exclude a sticky post from the top of the loop or completely remove them from the loop, we’ve created a custom code snippet.

Since this requires editing code on your website, it can be tricky for beginners. If you haven’t done this before, we recommend going through our guide on how to paste snippets from the web into WordPress for more details.

You might also consider hiring a developer for one-on-one help.

How to Ignore Sticky Posts in WordPress

This code ignores that a post is sticky and shows the posts in the normal order on your WordPress blog.

By using this code, your sticky posts will still appear in the loop, but they will not be placed on the top.

All you have to do is enter the following code to your theme’s functions.php file or in a code snippets plugin:

// The loop arguments
$args = array(
    'posts_per_page' => 10,
    'ignore_sticky_posts' => 1 
// The loop
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
    while ($the_query->have_posts()) {

We recommend adding this code with WPCode, the best code snippets plugin for WordPress. With WPCode, you can safely and easily add custom code in WordPress, without editing your theme’s functions.php file.

To get started, you need to install and activate the free WPCode plugin. If you need help, see this tutorial on how to install a WordPress plugin.

Once the plugin is activated, head to the Code Snippets » + Add Snippet page from your WordPress dashboard.

From there, find the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use Snippet’ button underneath it.

Add new snippet

Next, you can add a title for your snippet, which can be anything to help you remember what the code is for.

Then, paste the code from above into the ‘Code Preview’ box and select ‘PHP Snippet’ as the code type from the dropdown list on the right.

Paste code snippet into Code Preview box and choose code type

After that, simply toggle the switch from ‘Inactive’ to ‘Active’ and click on the ‘Save Snippet’ button.

Activate and save snippet in WPCode

Completely Exclude Sticky Posts From the Loop

Next, if you are using sticky posts in a slider plugin, then sometimes you might want to completely exclude your sticky posts from the loop.

Simply add the following code snippet to your functions.php file or in a code snippets plugin:

// The loop arguments
$args = array(
    'posts_per_page' => 10,
    'post__not_in' => get_option( 'sticky_posts' ) // do not display the sticky posts at all.
// The loop
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
    while ($the_query->have_posts()) {

This code will not display any sticky posts in the post loop.

You can follow the same steps as above to add this code using the WPCode plugin.

For more tips on modifying WordPress themes, check out our WordPress Theme Cheat Sheet for beginners.

We hope this article helped you learn how to exclude sticky posts from the loop in WordPress. You may also want to see our guide on how to get a free email domain and our expert picks of the best WordPress plugins.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

13 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. ogunrinde fatai says

    I am having similar issue with the broken pagination when removing the sticky post, does anyone has a fix thanks

  3. Stephen says

    I am having a problem that the one “sticky” post shows up as the first “featured” post so there is the same article listed twice in succession. Any help would be great.

  4. Kyle Shevlin says

    Don’t know if this happened for anyone else, but using this broke the pagination. My next page of posts would be a repeat of the first page. If this happened to anyone else, do you have a fix?

  5. Agus Almaula says

    Thank you so much, just because i am totally wpBeginner i came to this site and my WP development solved.


  6. Daniel Lemes says

    Both methods broke my pagination (page links still there, but load always the same posts), any idea on it?

  7. Rohit Tripathi says

    This is really great. One place where you don’t need this is when creating a custom sidebar widget to display recent posts.


  8. Kyle Shevlin says

    Is there any reason that adding this would remove the functionality of archives and tag cloud links? I, too, am trying to exclude sticky posts from my main blog loop using one loop to operate a featured section and a second to operate everything else. The trouble I’m having comes when I click on links in an archive section or tag cloud. It redirects me back to my first page again. When I remove this exclusionary code, it works just fine. Can’t figure this one out.

  9. chris mccoy says

    you can also use pre_get_posts so you dont have to alter your main loop.

    $query->set(‘post__not_in’, get_option(‘sticky_posts’));

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.