[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
parameter.

So right now I have
domain.com/coverage/vehicle/?sem=true

I need it to be
domain.com/coverage/vehicle/sem

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/([^/]+)/?$' =>
'index.php?pagename=sample-page&sid=$matches[1]');
    $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

domain.com/sem/sample-page


Can someone point me in the right direction?


-- 
thanks

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


More information about the wp-hackers mailing list