Documentation Change Your Pretty Permalinks or Add Custom Rewrite Rules

Change Your Pretty Permalinks or Add Custom Rewrite Rules

Permalinks are the permanent URLs to posts, categories, and other sections of your website. They generally look like this by default:

http://vip.wordpress.com/2012/09/04/new-liveblog-add-on/

http://vip.wordpress.com/category/plugins/

http://vip.wordpress.com/tag/liveblog/

URLs should be permanent and never change — hence the name permalink. When you’re first configuring your site though, you can modify them from the default structure. Some of the values you can use include:

%year% The year of the post, four digits, for example 2004
%monthnum% Month of the year, for example 05
%day% Day of the month, for example 28
%hour% Hour of the day, for example 15
%minute% Minute of the hour, for example 43
%second% Second of the minute, for example 33
%post_id% The unique ID # of the post, for example 423
%postname% A sanitized version of the title of the post (post slug field on Edit Post/Page panel). So “This Is A Great Post!” becomes this-is-a-great-post in the URI.
%category% A sanitized version of the category name (category slug field on New/Edit Category panel). Nested sub-categories appear as nested directories in the URI.

VIP

For WordPress.com VIP clients, if you’d like to customize these permastructs, you can use any of the following helper functions in your theme’s functions.php file:

/**
 * Enable a custom permastruct, if the site wants to use one that's not the WP.com default (/yyyy/mm/dd/post-name/)
 */
wpcom_vip_load_permastruct( '/%category%/%postname%/' );

/**
 * Enables a custom or no category base, if the site wants to use one that's not the WP.com default (/category/)
 */
wpcom_vip_load_category_base( 'section' );

/**
 * Enables a custom or no tag base, if the site wants to use one that's not the WP.com default (/tag/)
 */
wpcom_vip_load_tag_base( 'topic' );

Your theme’s rewrite rules are flushed automatically on every deploy (and when you switch themes), so you only need to worry about committing this change to the repository.

Custom rewrite rules can also be committed to your theme and incorporated in this manner.

Rewrite Rules Inspector #

rewriterules

A handy tool for testing and debugging your permastructs is the rewrite rules inspector. Enabled by default on WordPress.com VIP, this plugin features a complete list of your rules and a URL-matching tool to test your URLs. To find the inspector, visit VIP -> rewrite rules.

Note: if the inspector ever shows all or some of your rules in red and issues the “some rules are missing” error, click the flush rules button, and your rules should fully refresh.

Enterprise

Enterprise users have an admin interface for changing their permastructs. It appears at “Settings” -> “Permalinks”:

Enterprise permastruct screen