Site logo

Archived topic

Moving Sidebar below Page Title on Mobile

8 replies · Started by Hefin on November 26, 2019

Viewing posts 1–9 of 9

I saw related questions in the forum, but was not able to figure out how it has to be done..

So what we need to achieve here is on mobile we want the Sidebar to be visible under the Page Title.

Can you please assist me with the same?

Thanks.

Ahh..I did a dirty workaround, modified the theme file which I dont want to.. what i did right now was

1) Edited content-page.php and moved the Title code from there to page.php
2) added generate_construct_sidebars(); below the title code

Is there a cleaner method to do this without losing the changes when i update the theme

Another addition to the theme could be that Elements >> Have a Display Rules for Mobile Only?

Hi there,

you can use this CSS to remove the right sidebar on the mobile:

@media (max-width: 768px) {
    #right-sidebar {
        display: none;
    }
}

Then hook in your content with the hide-on classes that Leo provided.

Mobile conditionals are tricky and even trickier to add as a display rule in Elements - the logic required to create display rules is really complicated.

As an alternative to the above you can try just hooking in the following script to call the Sidebar using the wp_is_mobile funtion. Note this functions triggers on load, so don't expect it to do anything when resizing your browser:

<?php
if ( wp_is_mobile() ) {
    get_sidebar('right-sidebar');
}
?>

Thanks, I used

@media (max-width: 768px) {
    #right-sidebar {
        display: none;
    }
}

As i wanted it to go away even when resizing the window!

You're welcome

This archived topic is closed to new replies.