[wp-hackers] Rewrite rules after unknown url structure

Jesse Friedman me at jes.se.com
Tue Oct 22 15:49:11 UTC 2013

Hi Everyone

Thanks in advance for any help.

We have a plugin that turns all of our pages and CPT's into SEM landing
pages simply by appending ?sem=true to the end of the url.  Google has
recently decided to start declining our campaigns because of this

So right now I have

I need it to be

I have the following code, which works well to a point.

function add_query_vars($aVars) {
    $aVars[] = "sid";    // represents the name of the product category as
shown in the URL
    return $aVars;

add_filter('query_vars', 'add_query_vars');

function add_rewrite_rules($aRules) {
    $aNewRules = array('sample-page/([^/]+)/?$' =>
    $aRules = $aNewRules + $aRules;
    return $aRules;

add_filter('rewrite_rules_array', 'add_rewrite_rules');

The problem is that, this code assumes this parameter is only going to be
used on pages where pagename=='sample-page'

I need to be able to get the var on any page, post, cpt, etc...

I'm find with doing


Can someone point me in the right direction?


*jesse friedman*
jes.se.com *
Book: Web Designers Guide to WordPress -
Twitter: @professor <http://twitter.com/professor>
Facebook: Like<https://www.facebook.com/pages/Jesse-Friedman/204793299545174>

More information about the wp-hackers mailing list