Skip to content

Instantly share code, notes, and snippets.

@chellestein
Last active October 28, 2016 01:24
Show Gist options
  • Save chellestein/b08531ae1984971c3ac42fe1b1926ace to your computer and use it in GitHub Desktop.
Save chellestein/b08531ae1984971c3ac42fe1b1926ace to your computer and use it in GitHub Desktop.
WordPress Function to Exclude Categories from Front Page
<?php //
/**
* Do Not Include Above Opening PHP tag
* Copy/Paste Below code into functions file
* Replace the -1 to your unique category id number
* More than 1 category can be separated by a comma
*/
//* Function to Remove categories
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-1' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category_home' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment