Site logo

Archived topic

Disable section on mobile without CSS

10 replies · Started by Damiaan van Vliet on February 26, 2019

Viewing posts 1–11 of 11

Hi team,
I want to disable a section on mobile but not through CSS.
The best way would be through functions.php.
Because I want that section not to be loaded on the first place. And that is because it has a slider shortcode in it.

Is that possible?

Thanks!

Ah great David! Did not thought of a hook.
So you mean adding a slider shortcode to a hook instead of section I think?

Will try this but I'm pretty sure it will work one way or the other :-)

Yep, if you use the Hook Element you can then also control the Display rules, if there a pages you don't want it on.

You are a hero David! :)

I have this hook and works perfect.

<?php
if ( wp_is_mobile() ) {
	/* Include/display resources targeted to phones/tablets here */
} else {
	/* Include/display resources targeted to laptops/desktops here */
	echo do_shortcode('[slider id="001"]');
}
?>

Awesome - you can shorten it to:

<?php
if ( !wp_is_mobile() ) {

	echo do_shortcode('[slider id="001"]');
}
?>

! = not :)

Great David!

You're welcome

I've got an ACF text field that I've added shortcode support to so i could add a slider via shortcodes.

I basically want to do the same thing as this post.. not have the slider load or play on mobile (it's not loading anyways; just taking up bandwidth ruining the UX)
I don't see anything wrong with this code. I've manually placed it into archive-showcase.php

I'm I not seeing something? In your opinion should I put the !wp_is_mobile within the div???? Or is use Elements and hook?

thanks for input

			<?php if ( !wp_is_mobile() ) { ?>
    			<!-- Display and echo desktop stuff here -->
    			<div class="masterslideplugin-pro__container">
    				<?php 
    					$j66coslideshortcode02 = get_field('slideshow_ipad_pro');
						echo do_shortcode($j66coslideshortcode02);
    			 		?>
    			</div>				
    		<?php } ?>

			

OK. I tried it this way to. It didn’t make a difference.

    	
<div class="masterslideplugin-pro__container">
    <!-- Display and echo desktop stuff here -->
    <?php if ( !wp_is_mobile() ) {
    	$j66coslideshortcode02 = get_field('slideshow_ipad_pro');
	echo do_shortcode($j66coslideshortcode02);
	}
    ?>
</div>

Elements/hook wouldn't help with this. The function should be exactly the same.

I do find that the wp_is_mobile doesn't work all the time but the theme cannot control that:
https://developer.wordpress.org/reference/functions/wp_is_mobile/

I would recommend checking with the plugin's support team if they can offer a way to not load the slider on mobile.

Thanks for your understanding :)

This archived topic is closed to new replies.