WordPress: exclude categories from the Home Page

I don’t want my posts from categories “Softwares” and “Wishlist” to appear in the main thread of my blog. In the past, I had to add some code in the “functions.php” page of my theme (twentyeleven) to filter that posts from the home page. Now, I am using the plugin “WP Exclude From Homepage 1.1.2”.

Click to Read More

The code I used to add in \\<YourSynology>\web\wordpress\wp-content\themes\<YourTheme>\function.php was:

[code language=”php”]

/**
* Excludes post in category "softwares" from the home page
*/
function exclude_cat_from_home($query) {
if ( $query->is_home) {

$acats = array();
foreach ( array(‘wishlist’,’softwares’) as $catName ) {
$cat = get_category_by_slug( $catName );
$acats[] = ‘-‘.$cat->cat_ID;
}
$cats = join(‘,’, $acats);
$query-> set(‘cat’,$cats);
}

return $query;
}
add_filter(‘pre_get_posts’,’exclude_cat_from_home’);

[/code]

It was located at the very bottom of the file

Loading


Categories:

Tags:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *