Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    You should be able to deactivate the modules in specific situations, but in order to help you, I would need to know more about your setup. Do you use a specific theme on mobile, like Jetpack’s Mobile Theme module, or is your theme responsive?

    Thanks!

    Thread Starter ganch0

    (@ganch0)

    Hey

    My theme is responsive, so I don’t use the Jetpack’s Mobile Theme.
    How can I deactivate the modules in specific situations?

    Thanks!

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Thanks for the extra details. Try pasting the following in your theme’s functions.php file, or in a functionality plugin:

    // 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, and on the home page?
        if ( jetpackme_is_mobile() && is_home() ) {
            add_filter( 'sharing_show', '__return_false' );
        }
    }
    add_action( 'wp_head', 'jetpackme_maybe_add_filter' );

    That should do the trick!

    Thread Starter ganch0

    (@ganch0)

    It doesn’t work ??

    The idea was the sharing buttons to display only when the user is on the mobile version (theme).

    When I did what you told me, the sharing buttons appear on the mobile version, and also on the desktop version it displays the “Share with”.

    Thanks for your help so far!

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Oh, I’m sorry. The code snippet above does the opposite. It removes the buttons on mobile, and displays them on desktop. I should have read your post better.

    Give this a try instead. It works in my tests:

    // 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 desktop
    function jetpackme_maybe_add_filter() {
    
        // On mobile, and on the home page?
        if ( ! jetpackme_is_mobile() ) {
            add_filter( 'sharing_show', '__return_false' );
        }
    }
    add_action( 'wp_head', 'jetpackme_maybe_add_filter' );

    If you still experience issues, I’d recommend flushing your site’s cache if you use a caching plugin.

    Thread Starter ganch0

    (@ganch0)

    Great! It’s working perfectly!

    Thanks a lot!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to make Sharing Module active only on mobile?’ is closed to new replies.