Title: how do I add custom variable?
Last modified: August 30, 2016

---

# how do I add custom variable?

 *  [fnanetwork](https://wordpress.org/support/users/fnanetwork/)
 * (@fnanetwork)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/how-do-i-add-custom-variable/)
 * trying to get this to work
 * I need to be able to pass a custom variable to all the links as the visitor moves
   through the site ?rid=”a user id”
 * That way you can share your link wordpresssite.com/?rid=2 and people check it
   out and want to join you can give them a signup link with member.wordpresssite.
   com/?rid=2
 * I added 2 functions to the function.php
 *  `function add_query_vars_filter( $vars ){
    $vars[] = “rid”; return $vars; } 
   add_filter( ‘query_vars’, ‘add_query_vars_filter’ );`
 * and
 *  `function pass_rid () {
    if( !is_admin() && isset($_GET[‘rid’]) ) { $rid = $
   _GET[‘rid’]; $location = “[http://&#8221](http://&#8221);.$_SERVER[‘SERVER_NAME’].
   $_SERVER[‘REQUEST_URI’]; $location .= “?rid=”.$rid;
 *  echo $location;
    wp_redirect( $location );
 *  }
    } add_action(‘template_redirect’, ‘pass_rid’);`
 * I end up with endless loops
 * The echo is just to see if it is grabbing the variable

The topic ‘how do I add custom variable?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [fnanetwork](https://wordpress.org/support/users/fnanetwork/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/how-do-i-add-custom-variable/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
