I need a random redirect button just like 9gag.com. I know that i need a add a rewrite rule but i dont know how to do this

I tried to use plugins and other codes, but none worked.

closed as not a real question by s_ha_dum, kaiser, fuxia Jan 23 '13 at 19:12

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.


you can use this code

function random_add_rewrite() {
   global $wp;
   add_rewrite_rule('random/?$', 'index.php?random=1', 'top');

 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);

ANd then use this for random redirect

 <a href="http://.....com/?random=1/" >Random Post</a>
  • it looks like half of that code is not relevant to the answer – Milo Jan 23 '13 at 17:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.