Site logo

[Resolved] Stop Content loads when hidden

Home Forums Support [Resolved] Stop Content loads when hidden

Home Forums Support Stop Content loads when hidden

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #713489
    Todd

    At the bottom of the URL I’ve attached I have logos that I am NOT displaying using the built-in hide-on-mobile glass. Is there a technique or a way to hide this and also keep the content from loading on the devices it is hidden on?

    #713745
    Tom
    Lead Developer
    Lead Developer

    It might be possible to check what kind of device your visitor is using with PHP, but I’m not really sure of a good way to do it.

    You’d have to find a good way to check and then display those logos inside a shortcode or something similar so you could return false/empty if the user isn’t on a mobile device.

    #713838
    Todd

    I revised the link in the the first post for I am trying to get something to work on a test page.

    This inspired me to try and find a PHP solution. At the bottom of my test URL, I am trying to display the logos with a different hook. Unfortunately, I think I’m just hacking my way through the PHP. At the top of the page it is echoing some text based on mobile or desktop from another hook so I am getting somewhere…I think.

    I have tried putting the following PHP that calls upon the same PHP hook from this solution I found on this post.

    My PHP is as follows, it seems that no matter how I write it it creates an error I’ve also tried putting it in a short code and the trying to figure out how to Echo the short code and that did not work.

    <?php
    if(isMobileDevice()){
    //Your content or code for mobile devices goes here
    }
    else {
    //Your content or code for desktop or computers devices

    }

    #714502
    Tom
    Lead Developer
    Lead Developer

    So, assuming you’ve defined isMobileDevice() somewhere, you would do this:

    <?php
    if ( ! isMobileDevice() ) :
        ?>
            Your HTML in here
        <?php
    endif;
    #715075
    Todd

    I tried that and it is giving me an error at bottom of the page. In general it does seem to be working, since the following code in another hook seems to make the header at the top appear on this testing page.

    <?php
    if(isMobileDevice()){
        echo "It is a mobile device";
    }
    else {
        echo "It is desktop or computer device";
    }
    ?>
    #715736
    Tom
    Lead Developer
    Lead Developer

    What was the error?

    #715780
    Todd

    I put the link in the original post thread, it is at the bottom where I have the hook trying to display and it is the following:

    Parse error: syntax error, unexpected '<', expecting end of file in /home/curious9/public_html/tvtg164363/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()'d code on line 6

    #716017
    Tom
    Lead Developer
    Lead Developer

    Try this:

    <?php if ( ! isMobileDevice() ) : ?>
        Your HTML in here
    <?php endif; ?>
    #716069
    Todd

    I can get the following Ex 1 to work as a test and it is working as a hook at the top of the page. I just can not figure out how to do the same thing with a more complicated block of html as you see in Ex 2 without an error, it seems the class quotes are conflicting with the PHP?

    Also in Example 2, if I want nothing to appear in mobile do I just echo blank quotes?

    Example 1: Works as a test

    <?php
    if(isMobileDevice()){
        echo "<div><h2>This is a mobile device</h2></div>";
    }
    else {
        echo "<div><h2>It is desktop or computer device</h2></div>";
    }
    ?>

    Example 2: causes an error in italics

    <?php
    if(isMobileDevice()){
        echo "";
    }
    else {
        echo "<div class="hide-on-mobile grid-container logo-showcase-footer-1">
    <hr />
    <h2>Our Clients</h2>
    [logoshowcase show_title="false" image_size="full" extra_class="logo-showcase-footer-2" slides_column="6" dots="false" arrows="false" autoplay_interval="4000" cat_id="1925"]</div>";
    }
    ?>

    Parse error: syntax error, unexpected ‘hide’ (T_STRING), expecting ‘,’ or ‘;’ in /home/searcht1/public_html/vortechsgroup.com/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()’d code on line 6

    #716593
    Tom
    Lead Developer
    Lead Developer

    Do this instead:

    <?php if ( isMobileDevice() ) {
        echo "";
    } else { ?>
        Your HTML in here.
    <?php } ?>
    #716680
    Todd

    Tom, this fantastic, I got this to work and this solves a problem for me. I just sent a donation, not much but I sure appreciate your service and patience. Thank you.

    #716837
    Tom
    Lead Developer
    Lead Developer

    Thanks so much! I really appreciate it 🙂

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