from the blog.

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

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Esse site utiliza o Akismet para reduzir spam. Aprenda como seus dados de comentários são processados.