Genesis Themes

  • Home
  • Genesis Tutorials
  • WP Tutorial
  • Twenty Fifteen Theme
  • Social Media
  • WP Plugins

Exclude Category Posts from Homepage in WordPress

Exclude Category Posts from Homepage

Learn how to exclude one or multiple categories posts from displaying homepage or blog page of WordPress theme.We tested this code in WordPress twenty fifteen theme and other WordPress themes,it's working perfectly.

Add the following code to your WordPress theme's functions.php file and replace category ID number with your own category ID's.It's very easy to exclude category posts from Homepage in WordPress.

To exclude one category posts from homepage :

//Exclude Category Posts from Home Page
function themeprefix_exclude_category($query) {
if ( $query->is_home() ) {
$query->set('cat', '-11');//add your category number
}
return $query;
}
add_filter('pre_get_posts', 'themeprefix_exclude_category');

Replace -11 with your category ID in the above code.

To exclude multiple categories posts from WordPress home page :

//Exclude Category Posts from Home Page
function themeprefix_exclude_category($query) {
if ( $query->is_home() ) {
$query->set('cat', '-11, -12, -25');//add your category number
}
return $query;
}
add_filter('pre_get_posts', 'themeprefix_exclude_category');

Replace -11, -12 and -25 category ID's with your own categories ID's.

If you find any difficulties to add this code,let me know.I will help you.

Related Posts

  • Best Settings for Async JS and CSS WordPress Plugin
  • Top 10 Most Popular Google Adsense Alternatives 2016
  • How to Add Related Posts with Thumbnails in WordPress
  • Resources to Minify CSS in WordPress
  • Add Social Media icons to Twenty Fifteen WordPress Theme
  • How to Add Expires Headers in WordPress
  • Display WordPress Popular Posts by Comments Count
  • How to Create a WordPress Twenty Fifteen Child Theme
  • How to Display Google Adsense After First Post in WordPress
  • Specify a Vary: Accept-Encoding header in WordPress

Bluehost and Siteground Coupons for January 2016.

Best Premium WordPress Themes from TemplateMonster
download wordpress themes from MonsterOne

Categories

  • Blog
  • Blogger
  • Genesis Tutorials
  • Social Media
  • Top Websites
  • Twenty Fifteen WordPress Theme
  • WordPress Plugins
  • WordPress Tutorial