Archived topic
show the right sidebar elements just after the main content
3 replies · Started by Yassine on March 17, 2022
I have a GP Premuim and i'm using Volume site library Theme
I would like to show the right sidebar elements just after the main content, not below the comment section, when the user navigates on a mobile device...
On Desktop : Right Sidebar
Tablet and Mobile: after main content (directly after the end of the article)
Regards!
Hi Yassine,
You can use this CSS to not display the default sidebar on mobile:
@media (max-width: 768px) {
.site-content > #right-sidebar {
display: none;
}
Adding CSS: https://docs.generatepress.com/article/adding-css/
Then insert the sidebar before the comment using this PHP snippet:
add_action('generate_before_comments', 'inser_sidebar_before_comment');
function inser_sidebar_before_comment() {
if ( is_single() && wp_is_mobile() ) {
return get_sidebar();
}
}
Adding PHP: https://docs.generatepress.com/article/adding-php/
Hi Ying,
Thanks, it worked.
I also need to make a sticky sidebar (same element of the right sidebar, not a full sidebar), so I've used this plugin:
https://wordpress.org/plugins/q2w3-fixed-widget/
However, when I select the CSS ID of the element to make it sticky, it works but I do not want it to be sticky on mobile..
Best Regards!
Yassine
Use this selector: .site-content > #right-sidebar