• Resolved harshclimate

    (@harshclimate)


    I’ve run in to an issue with 'orderby' => 'rand' and browser behavior. Firefox behaves how I think rand should work, where when you’re clicking around the website and you come back to the index (home) page you’re seeing new posts but on Chrome, after clicking around and returning, the posts are the same. That is, until you refresh the page, then the posts change. Is there any way to make Chrome act like Firefox as far as this goes?

    I have a feeling this is more of an HTML issue than a wordpress issue but I just wanted to throw this out there to see if anyone has had the same ‘issue’?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Linards

    (@linardsn)

    This issue might be related to browser caching. Chrome could be caching the page, and when you navigate back to the homepage, it’s showing you the cached version instead of fetching a new version of the page with a different post order. To resolve this issue, you can try adding a cache-control header to your site to prevent browsers from caching the homepage.

    You can achieve this by adding the following code to your active theme’s functions.php file:

    function prevent_homepage_caching( $headers ) {
        if ( is_home() || is_front_page() ) {
            $headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';
        }
        return $headers;
    }
    add_filter( 'wp_headers', 'prevent_homepage_caching' );
    

    This code will modify the headers sent by your server for the homepage, instructing browsers not to cache it. As a result, when users return to the homepage, they should see new posts regardless of which browser they’re using.

    Please note that editing the functions.php file should be done with caution. Always back up your site and theme files before making any changes.

    Additionally, keep in mind that preventing caching for your homepage might increase server load and decrease your site’s performance, especially if you have a high amount of traffic. It’s essential to balance the desired behavior with the performance implications to ensure an optimal user experience.

    • This reply was modified 2 years ago by Linards.
    Thread Starter harshclimate

    (@harshclimate)

    That works! Thank you very much for the snippet! And I appreciate the heads up on the server/site performance. I’m fairly confident that my website will never generate any traffic but I love doing it anyway ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Interesting issue with ‘orderby’ => ‘rand’’ is closed to new replies.