I was able to solve this problem by adding the code below under my theme/functions.php file. (My custom post type slug is ‘news’)
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 );
function df_custom_rewrite_rule() {
add_rewrite_rule('(.*?)$', 'index.php?news=$matches[1]', 'top');
}
add_action('init', 'df_custom_rewrite_rule');
Related Posts:
- How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- Custom Post Type pages are “not found”
- Remove taxonomy slug from a custom hierarchical taxonomy permalink
- remove custom post type permalink
- Getting hierarchical custom post type permalinks to work just like pages
- Add .html (dot HTML) extension to custom post types
- Best way to flush_rewrite_rules for custom post type, in a mu-plugins plugin?
- Multiple post types – share same ReWrite slug?
- Removing unnecessary numbers appended to postname in permalinks
- Slug Formatting : Acceptable Characters?
- Custom post types – Use post_id in permalink structure when using has_archive => true
- How to handle a hierarchy with custom post types
- ‘publicly_queryable’ => false not working as expected for custom post_type
- How to modify URL structures in custom post types and taxonomies or terms
- Disable Single Post View for Specific Taxonomy on Custom Post Type
- array_pop() expects array, boolean given for $event_type_term ->slug
- Using %postname% tag with a Custom Permastruct creates 400 Bad Request Errors from the server
- custom post type permalinks with category and tags
- Make permalinks based on an ACF-field
- Custom permalink with pagination
- Can /%year%/%monthnum%/%day%/ structure tags be added to custom post type permalinks?
- Custom Permalinks for Custom post Type Archives?
- Change the url of Projects in Divi Theme
- Removing parent slug from URL on custom post type
- How to rewrite custom post type URL for multiple depths instead of one specific depth
- On clicking on the category name the page is redirecting on 404 pge
- wp_publish_post breaks permalinks
- Remove POST_TYPE from custom post type permalink
- WordPress Rewrite rule for nested post types
- Remove Taxonomy Slug when No Taxonomy is Assigned to Custom Post Type?
- Custom Post Type relationship with hierarchical parent and child permalinks
- Include taxonomy slug in url?
- Custom permalink – append taxonomy name and term name at the end of permalink
- Using a Custom Post Type Attachment as link
- Custom post types and permalink
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- custom post type and custom taxonomy url conflict
- Get a permalink structure of /%posttype%/%category%/%postname%
- Add hierarchical taxonomy to permalink for custom post type
- Custom post types, taxonomies, and permalinks
- How to specify URLS for custom posts & taxonomies
- Custom post types, taxonomies, and permalinks
- Customize permalink when creating a post
- Custom Post Type permalink shows wrong page: homepage/index.php
- Get term name and term parent into custom post type permalink
- Rewrite rules for custom posts types
- Does WordPress consider a post name unique if that same post name is in multiple Post Types?
- Custom post type as home page with custom url
- URL rewrite add author as base
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working
- CPT’s with landing page instead of archive – Url Rewrite?
- Hierarchical permalinks for custom post type and taxonomy
- How to organize hierarchical structure in custom post type with taxonomy (like with categories)
- Custom Post Type – Duplicate Page Slugs
- Remove permalink for custom post type
- Best way to specify “article type” in URL
- How to have permalink like domain.com/term/postname?
- Custom post type permalink returns 404 when set to private
- Custom post type slug 404
- How to filter a custom post type by custom taxonomy without 404
- how to retain the ability to modify the post slug after applying a post_type_link filter?
- Post type Permalink
- Pagination of custom post type leads to 404 error
- Custom permalink structure for remote content pages
- WordPress Custom URLs
- Adding an extra parameter [string] to my posts’ permalink?
- Custom Post Type nest under a normal WordPress Page
- Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?
- Permalinks not working (404) for the ‘item’ post type
- Wp PageNavi only works with default permalinks on a custom post type?
- Custom category URL not displaying posts
- Change permalink for custom post type?
- Use a different URL path / permalink for CPT
- Duplicate slug/permalink issue while adding same post name
- How to mass get post editor URLs
- Permalinks: custom post type -> custom taxonomy -> custom sub taxonomy -> post
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- % encoded URL giving 404 error in WordPress
- Issue with Custom Post Types and Permalinks
- How can i remove post type archive URL?
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- Links Image in “Catalog” Page to Posts
- Why does my plugin require a permalink reset after a new installation?
- How to have permalink structure based on taxonomy terms
- Custom post type permalink issue [duplicate]
- Multiple post types or single post type with category taxonomy?
- Get full control over custom post type url
- How to switch from custom post type URL to category URL?
- How can I add a “fake” parent into the permalink?
- Custom Post Type with /%shop_name%/gallery/%gallery% permastruct?
- Customizing the custom post type permalink
- Add category slug as class attribute in a link array
- Adding 2 CPT with multiple custom taxonomies to permalinks
- Custom Post Type permalink not working on new posts
- Storing postID in session variable to query database when visitor on custom template page
- Is it possible to remove the word “date” from archives?
- Custom Post Type – Rewrite slug [duplicate]
- Custom Post Type Permalinks with %category%
- Permalink for regular posts “/blog/”
- Permalink for Custom Post Types