Created
July 31, 2019 21:48
-
-
Save Farmatique/9d5d6288c114e081f23a940e4dd6fdbc to your computer and use it in GitHub Desktop.
Wordpress. Exclude post category from homepage or blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Remember the ID number of the category (in this case, the number is 55) | |
//Open functions.php file from the active theme | |
//Copy and paste the code and replace “xx” with the category ID (leave the minus sign in the code) | |
function exclude_category($query) { | |
if ( $query->is_home() ) {// set this to "is_archive()" to remove from blog | |
$query->set( 'cat', '-xx' ); | |
} | |
return $query; | |
} | |
add_filter( 'pre_get_posts', 'exclude_category' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment