Find out in this tutorial how to prevent the sidebar from loading on mobile in any Genesis child theme using code.
By default, the sidebar is loaded after the content in most WordPress themes, including Genesis child themes.
That’s why, on mobile devices, they always display the widgets after the content. But this doesn’t make much sense.
If you really want to display the sidebar content on mobile you probably want to display it before, as I explained in a previous tutorial.
But if you don’t really need to display the content, it’s best not to load it and thus decrease the loading time. This is always a good idea, especially on mobile.
Let’s see how to achieve it:
Code to prevent sidebar loading on mobile devices
Add the following code at the end of functions.php or in your functionality plugin:
With this block you prevent the
genesis_get_sidebar function, which is responsible for loading the sidebar with widgets, from being executed conditionally only on mobile (
Now, thanks to the
wp_is_mobile() function and the Genesis Framework functions and hooks, you can get the sidebar not to load on mobile devices if you are using a Genesis child theme.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉