Skip to content

Custom permalink structures

John Blackbourn edited this page Feb 18, 2016 · 3 revisions

Custom post types registered with WordPress' register_post_type() function don't allow for a custom permalink structure, unless you want to dive into the Rewrite API and pull your hair out in the process.

Extended CPTs allows a custom permalink structure to be specified via the permastruct parameter in the rewrite argument.

Examples

register_extended_post_type( 'article', array(

	'rewrite' => array(
		'permastruct' => '/foo/%custom_tax%/%article%'
	),

) );
register_extended_post_type( 'article', array(

	'rewrite' => array(
		'permastruct' => '/articles/%year%/%monthnum%/%article%'
	),

) );

All of WordPress' built-in rewrite tags are supported, including dates and custom taxonomies.

Rewrite Rule Testing

Extended CPTs automatically integrates with the Rewrite Rule Testing plugin by programatically generating a suite of test permalinks according to your specified permastruct. Sweet, eh?