[Support request] Remove Sidebar (completely) on mobile; cache issues

Home Forums Support [Support request] Remove Sidebar (completely) on mobile; cache issues

Home Forums Support Remove Sidebar (completely) on mobile; cache issues

  • This topic has 3 replies, 2 voices, and was last updated 3 years ago by David.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1687166
    Michael

    Hi,

    I used this code (via codesnippets) that I found elsewhere to completely remove my sidebar on mobile.

    add_filter( 'generate_sidebar_layout', function( $layout ) {
        // If we are viewing single post on mobile, set the sidebar
        if ( is_single() && wp_is_mobile() ) {
            return 'no-sidebar';
        }
    
        // Or else, set the regular layout
        return $layout;
     } );

    The issue is that occasionally WP Rocket is caching the mobile view and showing it on desktop. I THINK that maybe it’s because it’s deferring that particular piece of JS that’s controlling it. Does that sound right?

    If so, which JS should I exclude from deferring? Which one controls the sidebar?

    #1687243
    David
    Staff
    Customer Support

    Hi there,

    yeah thats a big issue with using the wp_is_mobile() function – any plugin or server that uses Page Caching may inadvertently serve up the the incorrect cached file. WP Rocket i believe has a separate Cache for the mobile – but before speaking with them its worth checking to see if your server is also performing Page Caching as they may conflict.

    #1687260
    Michael

    I suspect it is. I have litespeed installed on the server. And then Sucuri on top of that (set to minimal cache). Giant pain in the ass to get these all working together. Sucuri is worth it though just for the DDOS protection.

    #1687318
    David
    Staff
    Customer Support

    Yeah – sounds like a lot of opportunities for the element to be cached.
    Some instances, such as this , it may be better to use some CSS to hide the sidebar… i know it would be nicer not to load it but i can’t advise on how to overcome caching.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.