Whether your site uses Jetpack’s Mobile Theme or a responsive theme, it’s sometimes useful to remove sharing buttons on mobile. Since most mobile phones include built-in options to share a link on popular social networks, removing those buttons from your site can be a real performance gain on mobile.
To completely remove the buttons, we’ll use 2 Jetpack features: the sharing_show
filter, and a function named jetpack_is_mobile()
. That function allows you to detect whether your reader browses your site using a mobile device (with a Mobile User Agent).
// 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(); } // Let's remove the sharing buttons when on mobile function jetpackme_maybe_add_filter() { // On mobile? if ( jetpackme_is_mobile() ) { add_filter( 'sharing_show', '__return_false' ); } } add_action( 'wp_head', 'jetpackme_maybe_add_filter' );
Explore the benefits of Jetpack
Learn how Jetpack can help you protect, speed up, and grow your WordPress site.
Get up to 50% off your first year.
Compare plans