That’s how you can do first part of the job – get rid o CPT slug in post link (eg. news post type).
function df_custom_post_type_link( $post_link, $id = 0 ) {
$post = get_post($id);
if ( is_wp_error($post) || 'news' != $post->post_type || empty($post->post_name) )
return $post_link;
return home_url(user_trailingslashit( "$post->post_name" ));
}
add_filter( 'post_type_link', 'df_custom_post_type_link' , 10, 2 );
Now there should go a a rewrite rules for ‘news’, because you will get a 404 error.
Add the rewrite rule like this:
function df_custom_rewrite_rule() {
add_rewrite_rule('(.*?)$', 'index.php?news=$matches[1]', 'top');
}
add_action('init', 'df_custom_rewrite_rule');
Then we’ll need to flush rewrite rules, so go to Settings – Permalinks and save changes.
Related Posts:
- Mixing custom post type and taxonomy rewrite structures?
- How to rewrite URI of custom post type?
- Custom rewrite rules for archive page and single post
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Custom post types – Use post_id in permalink structure
- Custom Post Type and Taxonomy URL rewrite
- Custom post type permalink: only use %post_id% and remove %postname%
- Rewrite custom post type rss feed links
- Add category to custom post URL
- Creating a custom public user page
- Archive page with multiple taxonomies rewrite
- rewrite get parameter with custom post type
- How to filter custom post type archive by meta value
- Taxonomy archives based on Custom Post Type
- Multiple custom post types using the same taxonomy = URL frustrations
- Taxonomy page returns 404 page not found
- Child pages on hierarchical Custom Post Types 404s
- Remove unwanted part of permalink custom structure from CPT url?
- How to have a custom URL structure for a custom post type?
- Permalinks for CPT breaks permalinks to pages
- WordPress custom post type url change
- Changing a custom post type “has_archive” after registered
- Possible to change the slug of default post type?
- Custom Post Type rewrite redirects to homepage
- Custom Post Type slug same as page name causing a conflict
- Adding paged query to custom URL rewrite
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- Rewrite Custom Post Type URL slug
- Customising rewrite rules for CPT single post URL to work as paged URL
- Remove custom post type slug not working for child pages
- Custom WP TItle from custom template with dynamic URL structure
- Rewrite rules for custom post type slug
- Change URL of posts and also Custom Post Type
- Custom Post Type rewrite
- How to have custom post type /example/ and then posts /example/posts.html
- Remove url rewrites for registered taxonomies
- Change custom post type slug from plugin options
- 404 Issue w/ Custom Post Type – using Meta for Permalink rewrite
- Get Taxonomy Term Title by it’s URL
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- Custom rewrite url category
- Using taxonomy term in CPT permalink – Pages 404’s
- How to add rewrite rule to custom post type with parent in url with cpt ui?
- Programmatically rewriting slug through functions.php but returns 404
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Rewrite custom post type url – Multiple post types
- Why isn’t my custom post type archive URL translating?
- Rewrites/query for multiple hierarchical custom post types
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom post type’s permalink adds the name of the post type before the post name
- Custom taxonomy and post type with same slug
- Permalink misbehaving in Custom Post Types
- I can’t access custom taxonomy page listing
- Combine multiple CPT names to create valid permalinks
- Add term slug in URL of custom post type details page
- Programmatically add custom field to post_name in a custom post type
- How to rewrite custom taxonomy term archive to use THE SAME SLUG/front as CPT
- How to create custom search result page with custom URL parameters for custom post type?
- Page inside custom post type (url rewrite?)
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- How to constrain the results to a specific post_type on tag archive page?
- rewriterule not working
- Modifying rewrite rules to use /category//
- Custom Post Type View Button in Admin Gives 400 Error
- Custom Post Type URL Rewrite’s
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- restricting custom rewrite to just one custom post type
- returning the currect URL for nested posts
- 404 error rewrite permalinks
- Rewrite URL for CPT to domain/post-name/post-id
- Custom rewrite rule based on other custom post type title
- How to apply multiple rewrite_rule to a single custom post type url?
- Custom permalink structure for custom post types including multiple taxonomy
- How can I assign multiple parents to CPT?
- CPTs relationship
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Rewrite url for custom post type with specific url
- Customise Permalink Structure For Custom Post Types
- How to make “single post” permalink maintain it’s sub-page structure
- Custom Post Type canonical link / pagination redirecting to root
- Rewrite url post_tag for custom post type
- How to build overlapping custom post_type and taxonomy rewrites without conflicts?
- Two CPT: one is using part of the custom rewrite slug from the other
- WordPress custom post type rewrite rule matches all pages returning 404
- Rewrite Endpoint Url without ? before endpoint
- How Can a CPT in WordPress have a page 2 without an error?
- current_menu_parent for custom post type and custom url
- Remove sequential number from permalinks
- Parent cpt/child custom post type URL permalink relationship
- Custom post type and custom taxonomy archive inaccessible
- Custom Post & Taxonomy rewrite break regular post & page
- Custom archive URL as a subfolder of the custom post type slug
- Custom slugs with dates & IDs on Custom Post Type
- Add post id to url instead of WordPress default -2 suffix
- Custom URLs between different post types, using “Pods”
- CPT with URL rewrite showing as 404
- How to add random prefix (based on related page slug) to custom post type?
- Rewrite taxonomy permalink appended to CPT archive url