“random post” link not working after Cloudflare / Cache plugin active
-
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)
Viewing 1 replies (of 1 total)
- The topic ‘“random post” link not working after Cloudflare / Cache plugin active’ is closed to new replies.