Take an example custom post type called movie
the code below will create custom permalinks awesomemovies/
regardless of the one created by using the has_archive and rewrite options of register_post_type.
add_filter( 'rewrite_rules_array', 'custom_permalink_for_my_cpt' );
function custom_permalink_for_my_cpt( $rules ) {
$custom_rules = array();
// for archive urls
$custom_rules['awesomemovies/?$'] = 'index.php?post_type=movie';
// for individual post urls e.g: http://blog.com/awesomemovies/post-name/
$custom_rules['awesomemovies/([^/]+)/?$'] = 'index.php?post_type=movie&pagename=$matches[1]';
return $custom_rules + $rules;
}
For more information see WP_Rewrite
Related Posts:
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Custom post types – Use post_id in permalink structure when using has_archive => true
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- Custom Post Type Archives by Date with Custom Permalink
- Create permalink structure for one taxonomy archive per custom post type
- Tag Archive for Custom-Post-Type Posts yielding 404 when permalinks set to postname
- Problems with 404, .htaccess, permalinks and WordPress custom posts locally on Snow Leopard
- How can i remove post type archive URL?
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- Is it possible to remove the word “date” from archives?
- Custom post types not using archive structure
- How to have a dynamic slug and rendering the archive-{post_type}.php?
- Taxonomy, Terms, and Template Files
- Setting up custom post type archives in WP3.1? Any luck?
- Adding meta values to permalink
- How to show more posts on an archive page?
- Hierachical Custom post types permalinks not working
- Custom Posttype Inheritance (and url structure)
- Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error
- Can you have two CPTs with the same permalink structure?
- Display all custom post types in archives.php
- Custom Post Type Archives by Date (stored as meta value) WP3.1
- Rewrite permalinks for custom posttype and custom taxonomy
- How to check if last uri segment is a custom post type or taxonomy term?
- Including two taxonomies in a permalink structure
- WP Rewrite Rules – Custom post type & taxonomy
- Remove base slug in CPT & CT, use CT in permalink
- Permalink Structure problem with cpt and custom taxonomy
- Include Custom Posts Type in Year/Month/Date Archive
- Writing Custom Rewrite Rules that Incorporate Category for Custom Post Types?
- Add the .html extension to custom post types
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- Custom Permalink for Taxonimie and Custom Post Type
- Extend the wp_get_archives output with ‘?post_type=foo’?
- Custom Post Type with two hierarchical Custom Taxonomies: strategy to generate best permalink structure
- Custom Post Types and archives
- Function to get permalink of custom post type archives?
- How do I prefix blog post urls as mysite.com/blog/%postname%/ but allow authors to still be located at mysite.com/authors/%nicename%?
- Automaticly add slug to posts
- Different permalink for CPT and regular Posts/Pages but why?
- Custom post type, permalinks & pagination, going wrong
- Permalink Structure CPT With Custom Taxonomy Fails
- Bizarre Permalinks Issue: 404 Errors Everywhere
- Custom template page with custom archives listing by user
- Making a custom help center page
- Root slug of taxonomy returning 404
- WordPress Custom Post Type Repeated 404 Errors
- Child post with numeric only slug keeps redirecting to parent
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- WordPress custom post type permalink rewrite shows page not found
- Removing custom post type slug from URL
- Customize Custom Post Type URL
- Remove CPT name from permalink but add %category% instead
- How to have this permalink structure: post_type/postname/custom_inner_page
- Additional section in custom post type permalink
- Use the same date-based permalink structure for all post types
- “Post name” permalink returns home page for custom posts
- How to make permalink structure %category%/%postname%/ work for custom post type?
- Rewrite rule for Custom post type Monthly and Yearly archive
- menu link to custom post_type?
- Custom permalink with child taxonomy terms
- Custom post type posts don’t show in archive widget
- Archive for a Taxonomy of a Custom Post type
- How do you create %post_type%/%postname%/ permalink structure?
- How to get all posts related to particular category name on button click?
- Custom Post Type Archive template not being called
- Dynamic category name in query post
- Custom Post Type Archive Pagination
- How to setup a permalink structure for a custom post type
- Archive Template being used instead of Category Template for Custom Post Type
- add_query_arg() for custom post type on all visible links
- WordPress custom posts and permalinks
- Custom post type, permalink, add query variables problem
- How can I allow users to edit text that will be displayed on a custom post type archive page?
- How can I increase the post count for custom post types only?
- Is possible register two archive pages for single custom post type?
- CPT permalinks Rewrite
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Custom Post Type Archive Page showing as 404
- Modify category permalink to use post type slug
- CPT relations use in permalinks under single post type
- Custom Post Type Single Page and Archive Page redirects to Home Page
- How to change URL structure for custom post type in wordpress? Custom taxonomy + custom Post name [duplicate]
- hierarchical Custom post type child permalink not found
- Remove CPT Slug with 2 taxonomies and 1 post meta
- Allow duplicate permalinks slugs for custom posts by different authors
- Change wordpress url permalink structure to show authors posts
- Custom nav menu current item custom link problem
- Custom Post type and Taxonomy in post URL error
- Custom Post Type + Category archive
- Stop Custom post type from being searched via URL
- Multiple Custom Post Type permalink issue
- Custom Post Types and rewrite rules – One CPT works and a cloned one doesn’t
- archive-{custom_post_type}.php not getting recognized wordpress
- How to retrieve the permalink for a specific (custom) term?
- What is the proper way implement a global $wp_rewrite?
- Display results from two Custom Post Types in page template
- How can you preserve URLs when moving posts to a custom post type?
- Pagination not working for archive
- Show custom category archive as front page and remove taxonomy slug from urls