Intercept page request and add value to it

I am trying to intercept the GET request of a post and add a value to it.

function foo($request) {
    $request['vid'] = wp_generate_uuid4();

    return $request;
}
add_filter( 'request', 'foo' );

and hope that it would be available later with

$_REQUEST['vid']

but no access so far any ideas?

Topic request-filter pages posts Wordpress

Category Web


WordPress doesn't add the vid to the $_REQUEST array. Instead, it's saved in a class property — see WP::$query_vars which is an array.

And to access the value of items in that array, use get_query_var() like so in your case:

$vid = get_query_var( 'vid' );
echo "vid value is $vid";

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.