Skip to content

How To Exclude A Category From Jetpack Mobile Theme

In this tutorial, I’ll show how you can exclude a category from Jetpack Mobile Theme. It’ll exclude a specific category from being displayed in the mobile theme.

I’m looking forward to sharing some tricks to edit and customize Jetpack’s mobile theme, and this tutorial is the first in the series.

Just add following snippet to your current theme’s functions.php file:

// Check if we are on mobile
function jetpackme_is_mobile() {

    // Are Jetpack Mobile functions available?
    if ( ! function_exists( 'jetpack_is_mobile' ) )
        return false;

    // Is Mobile theme showing?
    if ( isset( $_COOKIE['akm_mobile'] ) && $_COOKIE['akm_mobile'] == 'false' )
        return false;

    return jetpack_is_mobile();
}

// Modify the main query on the home page for the mobile theme.
function jetpackme_modify_main_query( $arg ) {
    if ( jetpackme_is_mobile() && is_home() ) {
         $arg -> set( 'cat', '-1' );
    }
}
add_action( 'pre_get_posts', 'jetpackme_modify_main_query' );

You would need to replace the 1 in the above snippet with the ID of the category you want to exclude.

Leave a Reply

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