Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

Use a spacebar or arrow keys to navigate

WP_Rewrite Isn't As Scary As You Think

Erick Hitter

Team Custom Lead @ Automattic


About Me

What Does WP_Rewrite Give Us?


Pretty permalinks!


But How?


But How?


Okay, it's not really magic. Sorry to disappoint.


Instead, it's all about Regular Expressions.

But How?

WordPress uses the chosen Permalink structure to build Regular Expressions that translate a pretty permalink to arguments for WP_Query.


/2013/08/year-in-review/ becomes:

    'year'  => '2013',
    'month' => '08',
    'name'  => 'year-in-review',

Where Are These Regular Expressions?


In the database, specifically the options table.


The array of rewrite rules are stored in an option named rewrite_rules.



Rewrite Rule?!? Regular Expression?!?





Creating Your Own


You're in luck, WP provides lots of options!



Not an exhaustive list

Add a new rule: add_rewrite_rule()


add_rewrite_rule( $regex, $redirect, $position )



Add a new endpoint: add_rewrite_endpoint()


add_rewrite_endpoint( $endpoint )


add_rewrite_endpoint( 'feed' )


add_rewrite_endpoint( 'print' )

Modify WP_Rewrite behaviour


Use the generate_rewrite_rules action.


Modify rewrite rules


Use the rewrite_rules_array filter.






Slides are available at

Check Twitter for a link as well: @ethitter.