Prevent wordpress redirect / rewrite for certain pages

WordPress intelligently creates nice url for seo but there are times when you don’t want wordpress to redirect certain url. For eg, you might have a custom application in a protected area, hence having the old school url like blarblar.php?test=true&page=2 might be easier to work with. The trick lies in the parse_query hook.


function do_not_redirect_on_these_pages( $query ) {
  // print_r($query) for yourself to see.
  if( $query->query_vars['pagename'] == 'your_page' ) {
  remove_filter( 'template_redirect', 'redirect_canonical' );
  }
}
add_action( 'parse_query', 'do_not_redirect_on_these_pages' );

also avoid appending wordpress variables as query, such as s= , p=, post_type= …etc to save you some headaches. create your own variables.

Like it.? Share it:
Tags:

Comments are closed.