Site logo

[Support request] Add element with shortcode and diplay it just in mobile.

Home Forums Support [Support request] Add element with shortcode and diplay it just in mobile.

Home Forums Support Add element with shortcode and diplay it just in mobile.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2479953
    Rostyslav

    Hello,

    I am using slider evolution plugin that provides me a shortcode to insert. I insert it as element>hook>execute shortcode (display on homepage).
    I would like to display it just on mobile (with php function). (I don`t want to use css: hide-on-mobile because there is still a lot of requests from that plugin that make the website slow on mobile). I just want to make that plugin work just on desktop view.

    Thanks.

    #2479962
    Rostyslav

    As hero on desktop I am using a shortode from sliderrevolution inside a generateblocks container(block element) with css: hide-on-mobile.

    And as hero image on mobile, I am using a generateblocks styles with css: hide-on-desktop.

    On this image there is a view of mobile and all the html and css from slider-revolution is showing.
    https://ibb.co/0ZHvYXf

    I would like to remove all that code on mobile maybe with element hooks with display rules.

    #2480107
    Fernando
    Customer Support

    Hi Rostyslav,

    In your Hook Element, add this at the very top of the code input box:

    <?php if( wp_is_mobile() ) { ?>

    Then, add this at the very bottom:

    <?php } ?>

    Your overall code should look something like this:

    <?php if( wp_is_mobile() ) { ?>
    
    [YOUR_SHORTCODE_HERE]
    
    <?php } ?>

    Make sure enable PHP is toggled on in the Hook Element settings.

    #2480551
    Rostyslav

    Hello!

    Doesn’t work at all.

    Thanks

    #2480635
    David
    Staff
    Customer Support

    Hi there,

    wp_is_mobile() is a core function, that will only fire when the page is first visited from a client that matches that function.

    This means using responsive views in a browser will not apply to it.

    It also means its prone to caching issues ie. if your site/server has any kind of page caching then it must have a separate cache for mobile and for desktop. Otherwise the server will deliver whatever code was cached after the first visit.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.