• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » How to Exclude Posts from a Particular Category at WordPress Home

By Abhishek Ghosh June 6, 2022 5:27 pm Updated on June 6, 2022

How to Exclude Posts from a Particular Category at WordPress Home

Advertisement

Usually, we use a semi-static webpage for WordPress home. It is a quite natural fact that we want to highlight posts from certain categories on the WordPress home page. For various reasons, we need to publish a few articles “irrelevant” to the site’s niche. For the sake of SEO, we should try to exclude such posts from our WordPress home page.

In case you want the sponsored posts not to appear on your home page for a few days, then you should create a new category to temporarily show the posts. You have to manually move to the “vanishing category” after a certain time so that the home archive does not have the articles.

 

How to Exclude Posts from a Particular Category

 

First, there is an excellent plugin named “Ultimate Category Excluder”. You can search for this plugin from your WordPress “Add New” plugin page or visit the official repository at WordPress.ORG :

Advertisement

---

Vim
1
https://wordpress.org/plugins/ultimate-category-excluder/

All you have to do is, activate the plugin and navigate to the settings page of the plugin. Usually, this is the last part of the URL:

Vim
1
2
3
/wp-admin/options-general.php?page=ultimate-category-excluder.php
## example
# https://example.com/wp-admin/options-general.php?page=ultimate-category-excluder.php

Use this page to select the categories you wish to exclude and where you would like to exclude them from such as home page, feed, all archives, search etc. Remember that this will not vanish the articles from the search engine result page. This plugin is slightly a bigger hammer for our needs.

 

Snippets to Exclude Posts from a Particular Category

 

If you add the below snippet to your theme’s functions.php file, it will vanish the articles from the category you’ll mention from WordPress homepage:

Vim
1
2
3
4
5
6
7
8
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-2' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category_home' );

Please notice this line:

Vim
1
$query->set( 'cat', '-2' );

Here we have mentioned the category as minus 2. If you want to exclude category 15, then you should mention as minus 15 :

Vim
1
2
3
4
5
6
7
8
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-15' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category_home' );

If you want to vanish articles from multiple categories, then you can simply add then after a comma mark:

Vim
1
2
3
4
5
6
7
8
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-15, -2, -10' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category_home' );

Remember that the below format is incorrect :

Vim
1
'cat', '-15', '-2', '-10'

In our one old article, we mentioned about a plugin to avoid adding snippets on theme‘s functions.php file.

How to Exclude Posts from a Particular Category at WordPress Home

You can use that plugin to add the above code. Also, I have kept a ready to use plugin at GitHub repository for your testing.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Exclude Posts from a Particular Category at WordPress Home

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • WordPress & PHP : Different AdSense Units on Mobile Devices

    Here is How To Serve Different AdSense Units on Mobile Devices on WordPress With PHP. WordPress Has Function Which Can Be Used In Free Way.

  • Changing Data With cURL for OpenStack Swift (HP Cloud CDN)

    Changing Data With cURL For Object is Quite Easy in OpenStack Swift. Here Are Examples With HP Cloud CDN To Make it Clear. Official Examples Are Bad.

  • OpenStack Swift & HPCloud CDN PHP Bindings : Basics

    Here is the basics of OpenStack Swift & HPCloud CDN PHP Bindings for the WordPress Plugin developers and those who works with PHP based CMS.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy