add_rewrite_rule doesn’t work for me


I’m trying to use add_rewrite_rule to make custom URL.
My problem is the same as here : Custom Rewrite with Query vars

But I tried the 2 solutions, and it doesn’t work for me.

For testing, I installed locally a new version of wordpress with default theme Twenty fifteen. I installed the plugin Rewrite rules Inspector to see all the active rules.
I added a page “test” and added this function in function.php :

add_filter( 'query_vars', 'query_vars' );
function query_vars( $vars )
    array_push($vars, 'information');
    return $vars;

add_action( 'rewrite_rules_array', 'rewrite_rules' );
function rewrite_rules( $rules )
    $newrules = array();
    $newrules[ 'test/information/people/?$' ] = 'index.php?pagename=test&information=people';

    return $newrules + $rules;

I don’t forget to flush the new rules.

But when I go to :

wordpress write the url :

and not :

Why ? What’s wrong ?
It seems that WordPress has a rule over mine.
I don’t understand …Help !

nicocube 6 years 2015-09-28T08:55:21-05:00 0 Answers 75 views 0

Leave an answer