• abreusky

    (@abreusky)


    Hey!

    I am designing a blog exquisite.style and there is a link on the header menu that displays a random post each time you click on it.

    I created a plugin with the following code:

    <?php
    
    add_action('init','random_add_rewrite');
    function random_add_rewrite() {
           global $wp;
           $wp->add_query_var('random');
           add_rewrite_rule('random/?$', 'index.php?random=1', 'top');
    }
    
    add_action('template_redirect','random_template');
    function random_template() {
           if (get_query_var('random') == 1) {
                   $posts = get_posts('post_type=post&orderby=rand&numberposts=1');
                   foreach($posts as $post) {
                           $link = get_permalink($post);
                   }
                   wp_redirect($link,307);
                   exit;
           }
    }

    The Random Post link on the menu was this one: https://mydomain.com//index.php?random=1

    After I activated Cloudflare (with html, css, and js minification), the random post button/link is not working anymore. I also activated a caching plugin.

    Does anyone have an idea of how I can fix this and make the random post link work again?

    Thank you guys!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    If your link was pasted accurately with a double slash mydomain.com//index.php, that could be the problem. Many servers overlook malformed links like this, but added security measures could be blocking such requests. It’s only the slashes before index.php that’s the problem. After http: is normal.

Viewing 1 replies (of 1 total)
  • The topic ‘“random post” link not working after Cloudflare / Cache plugin active’ is closed to new replies.