Existing category-exclusion plugins are either borked, or overly aggressive. I needed one that would filter a category from the front page and main rss feed while still allowing category display and category rss feeds.

Basically, I followed the recipe at WordPress Codex: Custom Queries. The code isn’t generalizable enough to offer as a downloadable plugin. But here’s the gist. It’s 1 line of code, wrapped in a conditional if statement. Rocket surgery.

Put the file below into wp-content/ephemerator/ephemerator.php (or download a copy here)

add_action( 'pre_get_posts', 'ephemerator_remove_ephemeral_cat' );

function ephemerator_remove_ephemeral_cat( $wp_query ) {

$ephemeral_category = '1658'; // category id for my 'ephemera' category
    // kick in, to remove the ephemeral category if and only:
    // if we're loading the home page,
    // or we're loading a feed (but not a category feed)
    // or we're loading an archive feed (but not a category listing page)
    if ( is_home() || ( is_feed() && !is_category() ) || ( is_archive() && !is_category() )) {
        set_query_var('cat', '-' . $ephemeral_category);

2 thoughts on “Ephemerator”

Comments are closed.