That /news/
part is called front base and it could also be /foo/bar/
, i.e. having multiple "folders", and if you don't want the front base to be prepended to the permalink of posts in your post type or terms in your custom taxonomy, then set with_front
in the rewrite
argument to false
, like so:
// Register the "directory" post type.
register_post_type( 'directory', array(
'label' => 'Directories',
'public' => true,
'rewrite' => array(
'slug' => 'directory',
// If the front base is /news/ and this is true (which is the default value),
// then the post permalink would be example.com/news/directory/<post slug>.
// So set this to false if you don't want the /news/ in the permalink.
'with_front' => false,
),
) );
// Register the "location" taxonomy.
register_taxonomy( 'location', 'directory', array(
'label' => 'Locations',
'public' => true,
'rewrite' => array(
'slug' => 'directory/location',
// If the front base is /news/ and this is true (which is the default value),
// then the term permalink would be example.com/news/directory/location/<term slug>.
// So set this to false if you don't want the /news/ in the permalink.
'with_front' => false,
),
) );
And then be sure to flush the rewrite rules by simply visiting the Permalink Settings page. (No need to click on the Save Changes button, unless of course if you changed something in the form on the page)
post_tag
taxonomy and you want another permalink structure withdirectory
being the base, e.g.example.com/directory/tag/foo-tag
? That would lead to duplicate content penalty because both URLs would display the same posts? Or did you wantdirectory/tag/foo-tag
to show only posts in your CPT that are tagged withfoo-tag
?directory_tag
? That way, you'd be able to set the permalink structure todirectory/tag/foo-tag
all without the extra work of registering custom rewrite rules and filtering the tag link so that it uses thedirectory
base.directory/location
, but just change it to whatever you want)