• I have written a page that will (when fully enabled) allow me to show dynamic content.

    This content is dependant and a variable (side) that I want to pass from the address line

    i.e. https://www.arufc.com/?page_id=718&side=2nd%20XV

    this opens the page but does not pass the variable side.

    Do I need to globally register the variable somewhere?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Yes. When I first looked into doing this, it was near impossible to find information on it, but here is a method I use.

    Add this to a plugin, or your theme’s functions.php file:

    function add_query_vars ( $vars ) {
    	$vars[] = "side";
    	return $vars;
    }
    
    add_filter('query_vars', 'add_query_vars');

    That will ‘tell’ WP to look for a new query var called ‘side’

    Then in your code, you can use this function to get the value passed:

    get_query_var("side");

    Now if you want to integrate that data into permalinks, it gets a good bit tricker.

    Is there any way to register a user variable as a global (and so be able to access it from other pages WITHOUT passing it on the query string)?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pass address line variables to my page’ is closed to new replies.