Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i developed a plugin (the backend at least) and now i want to add a frontpage to my blog. the url should look something like this

all this three urls should point to a plugins function or a php site with a loop, i dont know. the params should be readable , i think with get_query_var

i played a bit with the following:

// Adding a new rule
function gamecard_insertMyRewriteRules($rules) {
    $newrules = array();
    $newrules['(gamecard)/(\d*)$'] = 'index.php?pagename=$matches[1]&gamecardslug=$matches[2]';
    return $newrules + $rules;

// Adding the id var so that WP recognizes it
function gamecard_insertMyRewriteQueryVars($vars)
    array_push($vars, 'gamecardslug');
    return $vars;

something is happening, but i stuck a bit.

somebody can give me a pointer how to get all this done?


share|improve this question

1 Answer 1

Well this one is tricky.

function my_plugin_query_vars($vars) {
    // add mypluginname to the valid list of variables
    $new_vars = array('mypluginname');
    $vars = $new_vars + $vars;
    return $vars;
add_filter('query_vars', 'my_plugin_query_vars');

this will tell WordPress to accepts GET variables with the name mypluginname. so now you can process requests like

We add an action on parse_request which gives us first change to parse given request before WordPress does.

function my_plugin_parse_request($wp) {
    // only process requests with "mypluginname=param1"
    if (array_key_exists('mypluginname', $wp->query_vars) 
            && $wp->query_vars['mypluginname'] == 'param1') {
add_action('parse_request', 'my_plugin_parse_request');

Then we need to add a hook in WordPress rewrite system and then create a rule that tell WordPress to forward all requests to


with this code

add_action('generate_rewrite_rules', 'my_plugin_rewrite_rules');

function my_plugin_rewrite_rules( $wp_rewrite ) {
  $new_rules = array('mypluginname/param1' => 'index.php?mypluginname=param1');
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

this should get you going :) so i hope this helps.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.