Skip to content
Advertisement

Force WordPress to ignore the w url parameter

Say, I have a WordPress installation running at example.com and have the following url

http://example.com/blah?w=100

Now, I want WordPress to ignore the w=100 part because, every time I pass a numeric argument to w, WordPress redirects me to the single page, I assume this has something to do with Attachments.

I can’t rename w to anything else because it is out of my control, my site has to work with a third party application that will not let me alter this condition.

I tried this

add_filter('request', array($this,'on_request'));
function on_request($vars){
  unset($vars['w']);
  return $vars;
}

And it wouldn’t work – any advice on this please ?

Advertisement

Answer

Alright, I solved it myself.

add_filter( 'request', 'alter_the_query' );
function alter_the_query( $request ) {

    unset($request['w']);
    return $request;
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement