Site logo

Archived topic

Stop Content loads when hidden

11 replies · Started by Todd on October 29, 2018

Viewing posts 1–12 of 12

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?

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.

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

}

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

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

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";
}
?>

What was the error?

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

Try this:

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

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

Do this instead:

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

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.

Thanks so much! I really appreciate it :)

This archived topic is closed to new replies.