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

How to Exclude Latest Post From the WordPress Post Loop

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 the latest post from the WordPress post loop?

By hiding the most recent post, you get the freedom to show this content in other locations across your website. You can even add your own styling so that the latest post always stands out on your homepage and blog archives.

In this article, we will show you how to exclude the latest post from the WordPress post loop.

How to exclude latest post from the WordPress post loop

Why Exclude the Latest Post from the WordPress Post Loop?

By default, WordPress displays your blog posts to visitors in reverse chronological order, so the newer posts appear first. However, you may want to change how the latest post looks on your custom home page or WordPress archive page.

By excluding the latest post from the WordPress post loop, you can show that content in a different location and even add your own custom styling.

With that said, let’s see how you can hide the latest blog post by excluding it from the WordPress post loop. Simply use the quick links below to jump straight to the method you want to use:

The easiest way to exclude the latest post from the post loop is by adding code to your WordPress website.

Some guides will tell you to edit the theme files manually, but this can cause common WordPress errors and may even completely break your website.

For that reason, we recommend using WPCode. It is the best code snippet plugin that makes it easy to add custom code in WordPress without putting your site at risk.

First, you will need to install and activate the free WPCode plugin. For more information, see our step-by-step guide on how to install a WordPress plugin.

Once the plugin is activated, go to Code Snippets » Add Snippet.

Adding custom code snippets to WordPress

Here, you will see all the pre-made snippets you can add to your site. These include a snippet that allows you to completely disable comments, upload file types that WordPress doesn’t usually support, disable attachment pages, and much more.

You can now hover your mouse over the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button when it appears.

Adding a custom code snippet to your WordPress website using WPCode

On the next screen, type in a title for the code snippet. This is just for your reference, so you can use anything you want.

Then, you must open the ‘Code Type’ dropdown and choose ‘PHP Snippet’.

Excluding latest blog from the WordPress post loop

With that done, simply paste the following into the code editor:

<?php
function wpsites_exclude_latest_post( $query ) {
	if ( $query->is_home() && $query->is_main_query() ) {
		$query->set( 'offset', '1' );
	}
}

add_action( 'pre_get_posts', 'wpsites_exclude_latest_post', 1 );

After that, scroll down the page to the ‘Insertion’ section.

If it isn’t already selected, then choose ‘Auto Insert’ and ‘Run Everywhere’.

Automatically inserting code into a WordPress website

Finally, scroll to the top of the screen and click on the ‘Inactive’ slider so that it shows ‘Active’.

Then, just click the ‘Save Snippet’ or ‘Update’ button to make the code snippet live.

Excluding latest blog from the WordPress post loop using WPCode

Now, if you visit your WordPress website, then the latest blog post will be hidden.

Method 2: Editing WordPress Theme Files (No Plugin Required)

Notes: This tutorial will only work with classic WordPress themes, as block themes have a different set of theme files. If you use a block theme, then we suggest using the first method.

We also recommend backing up your website first and/or using a staging environment to prevent errors when following this method.

Another way to exclude the latest post from the WordPress post loop is by adding code to your WordPress theme files.

This achieves a similar result to the code above, but you will need to add it directly to the WordPress loop where you want it to display.

For example, if you want to change the post loop across your website, then you will need to add the code to your index.php file.

Just be aware that adding code directly to your WordPress files can potentially cause issues with pagination on your WordPress blog.

First, you need to open your WordPress hosting provider’s file manager or connect your website with an FTP client.

For this tutorial, we will use Bluehost‘s file manager as the process is much easier than using an FTP. That said, the steps are more or less the same regardless if you use an FTP or a different web host.

If you are a Bluehost user, log in to your hosting account dashboard and navigate to the ‘Websites’ tab. Then, click ‘Settings’ on the website you’d like to edit.

Bluehost site settings

Now, go to the Quick Links section.

Then, click the ‘File Manager’ button. Bluehost also shows you your website’s root directory if you need it.

Accessing a website's file manager in Bluehost

Once you’re inside the file manager, you need to locate the file you want to edit. Let’s say you want to add the code to index.php, then you will find it in your current theme’s folder, which is inside public_html/wp-content.

Once there, just right-click on the index.php file and click ‘Edit.’

Opening the index.php file in Bluehost file manager

Now, you will need to copy the following code and add it to your WordPress loop:

query_posts('posts_per_page=6&offset=1');

This code tells the loop to only show 5 posts following the most recent post.

You will need to add the code directly above your WordPress loop so it will look similar to the code snippet below:

<?php
query_posts('posts_per_page=6&offset=1');
if ( have_posts() ) {

	// Load posts loop.
	while ( have_posts() ) {
		the_post();

		get_template_part( 'template-parts/content/content', get_theme_mod( 'display_excerpt_or_full_post', 'excerpt' ) );
	}

	// Previous/next page navigation.
	twenty_twenty_one_the_posts_navigation();

} else {

	// If no content, include the "No posts found" template.
	get_template_part( 'template-parts/content/content-none' );

}

Here’s what our code looks like in the Bluehost file manager:

Adding code to exclude the latest post in Bluehost file manager

Once you’ve added the code, simply click the ‘Save Changes’ button.

Then, go ahead and preview your WordPress website.

We hope this article helped you learn how to exclude the latest post from the WordPress loop. You may also want to see our guide on how to make money online blogging with WordPress or our expert picks for the best drag and drop WordPress page builders.

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

42 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. BGH_ says

    Hey guys, thanks for this article! I want to implement this, but whenever I try I’ve got an strange problem: entries would look like exactly like the frontpage, showing a list of recent post rather than the post itself. My code is slightly different, since is a SMTheme. Any help will be much appreciated. PS: Sorry for posting twice, but the code has printed wrong. Here you go:

  3. space says

    Solution is work fine, Thanks. but pagination broke after applying this code, I have tried but not able to work with correct pagination. Any solution to pagination ? .

    • Rickie Anand says

      apply class to the li as per the number of page and a counter & give style to p1c1 as display:none;

  4. Sabi Maharjan says

    I have used two plugins. One is “Recent facebook post” to show recent posts in wprdpress and “Facebook publish page” to publish my wordpress posts in facebook . Now I want exclude the recent post of the facebook that was already posted from my wordpress posts .

    How can I do it ?

    • WPBeginner Support says

      For that your plugin posting content from your Facebook page should have a check to see if a post was already published from WordPress to Facebook. We do not recommend users to directly edit plugin files. However, if you are comfortable editing php files then you can fork the plugin as a new plugin and then add the code to accomplish this.

      Admin

  5. Pastor Wynn says

    Thanks for the great tip. I had spent hours trying to figure this out, and you made it so simple!

  6. Jim says

    Hmm, when i tried this code on a category page loop, it couldn’t keep the posts for only that category, instead it acted as if it was the front page loop and displayed all posts.

  7. PabloCovarrubias says

    hello, i just have one question, when i do this, pagination doesen0t work anymore, how can i fix this?

    thanks, other than that, it works perfectly!!

    cheers!

    • space says

      Yes, pagination not working. you have found any working solution for pagination, I am still searching .. :(

        • de hams says

          pagination do not work on index page most so we can make out own ajax pagination call and mostly query_posts() works for pagination rather then WP_Query()

  8. Wordpwess says

    Is there a way to offset a post from one cat?

    E.g I want to show all posts apart from the LATEST post of category x

  9. Khurram says

    “query_posts(‘posts_per_page=6&offset=1’);” this is not worked for me , while i am using the WP-PageNavi plugin for page navigation. :(

  10. Ken says

    Thanks for the info. Worked well :) Though, I’m encountering another issue for another site I’m currently doing. Is there a way to exclude from the loop only the latest post of a particular category?

    Thing is, I’ve a blog that publishes podcasts. The front page highlights the most recent podcast – posts are published under category: Podcast – via its own styling. At the same time, the front page also shows the last 5 most recent posts, of which may include posts under the category “podcast”. I just don’t want to show in the loop the most recent post published under “Podcast” simply because it’s already featured with it’s own styling. Hope you can help me out. thanks!

  11. Joffrey says

    Thanks for the tip!
    But I was wondering if there is also a way to exclude the post that is currently showed on screen.

    If yes, can you tell me how to do this?

    Thanks in advance!

      • Joffrey says

        One of my pages displays first of all the latest or current post the user is viewing.

        The current post is called by the loop.

        Below this post I want to display the excerpts of other previous posts without the current post displayed in this list.

        The previous post-excerpts are called by query_posts:

        query(‘showposts=3&cat=5’);
        while($previousPosts->have_posts()) : $previousPosts->the_post();
        ?>

        As you can see I call 3 posts(excerpts) from category 5 which displays three posts from category News. This seems ok but within these 3 post-excerpts, the current post which is called by the loop is also in this list.
        Do you know a way to exclude the current post within this list?

        Thanks again!

        • Joffrey says

          Thanks again for the quick response!
          However, I did try the offset=1 in the query, only thing is that when you press an older post, you get to see the older post in the main loop, within the list excerpts the latest post is excluded, but the older post which is now the current post is still in the excerpts list.

          Any idea how to exclude not the latest but the current post?

          Thanks so far already :)

  12. Bilal Ahmed says

    Thank you so much for this piece as i was looking for a way to exclude 4 latest posts form my home page and i got answer by this articles and i have replaced (query_posts(‘posts_per_page=6&offset=1’);) by query_posts(‘posts_per_page=6&offset=3’); and its done :)

    • Editorial Staff says

      That is a multi-step process. First you would need to have a custom page template. Second you would need to create that custom page, your front page. Then you would run a query on that custom template showing only sticky posts.

      Admin

Leave a Reply to Jeremy Cancel 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.

WPBeginner Assistant
How can I help you?

By chatting, you consent to this chat being stored according to our privacy policy and your email will be added to receive weekly WordPress tutorials from WPBeginner.