3 Ways To Remove or Exclude Posts From Your Home Page Loop

There’s at least 3 ways you can exclude one or more single posts from your home or posts page depending on your Reading Settings.

  1. You can use CSS code
  2. You can use PHP code
  3. You can use a plugin

CSS Code

The easiest way to remove a specific post from your home page is to use CSS code in your child themes srtyle.css file.

.home .post-37401 {
display: none;
}

Simply grab the post i.d from your source code and replace it in the code above.

PHP Code

Another method is to use the posts i.d’s in a custom function in your child themes functions.php file:

add_action( 'pre_get_posts', 'wpsites_remove_posts_from_home_page' );
function wpsites_remove_posts_from_home_page( $query ) {

    if( $query->is_main_query() && $query->is_home() ) {
        $query->set( 'post__not_in', array( 37401, 37403 ) );
    }
}

Simply replace the post i.d’s in the code above with your own.

Plugin

If you looking for a non coding option, there’s several plugins which get the job done, one of which is Simple Exclude.

Related Solutions


Comments

2 responses to “3 Ways To Remove or Exclude Posts From Your Home Page Loop”

  1. Keith Davis Avatar
    Keith Davis

    Hi Brad
    Good to see you are working through the holiday and thanks for more useful tips and coding.

    1. Brad Dalton Avatar
      Brad Dalton

      My pleasure Keith. Thanks for all your comments.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.