Site logo

Archived topic

Disabling right sidebar on just mobile homepage and not posts

10 replies · Started by Puneet on January 4, 2022

Viewing posts 1–11 of 11

Is it possible to disable the right sidebar on just the Mobile Homepage but not in posts?

Homepage URL: https://geekyfi.com/

Hi Puneet,

Try this:

add_filter( 'generate_sidebar_layout', function( $layout ) {
    if ( is_home() && wp_is_mobile() ) {
        return 'no-sidebar';
    }

    // Or else, set the regular layout
    return $layout;
 } );

The above filter didn't work. I can still see the sidebar on the mobile homepage, below the Load More button. I am not using a static homepage, so, does the filter accommodate that factor?

Regards,
Puneet

Sorry, Ying,
I just rechecked, and the filter works perfectly. I guess it needed me to clear the cache more than once. Thanks a lot, closing the ticket.

Regards,
Puneet

Another issue happened with that filter. The sidebar disappeared from the desktop homepage as well. Here is the screenshot:-

https://snipboard.io/ZECnQH.jpg

I am removing the filter for now. Any other suggestions pls will be appreciated.

Regards,
Puneet

Hi there,

use CSS:

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

The filter and the wp_is_mobile() function will require your site/server having separate page caches for Mobile and Desktop. As what you're experiencing is a cached page being served.

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

Wouldn't this remove the sidebar from the entire mobile site including posts? The problem is I need to remove the sidebar from the mobile homepage only.

So, I just use the CSS and not the filter?

Just used the CSS without the filter. Seems to be working. Thanks a lot, David.

Regards,
Puneet

Thats correct - just the CSS.
Glad to be of help!

This archived topic is closed to new replies.