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:
- Rewriting a custom-post-type permalink with taxonomy term?
- Custom post type, no need for single view, plus want permalink rewrites that include hash in URI
- Custom post type yearly/ monthly archive permalinks
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- How can I rewrite URLs to pass taxonomy and post type values to the query?
- Using /%postname% for a custom post type
- Changing the URL Structure of a Paginated Custom Post
- Removing base slug from hierarchical custom post type
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- Adding meta values to permalink
- Custom post type taxonomies URL rewrite
- Custom Posttype Inheritance (and url structure)
- Permalinks so that one custom post type appears to be a child of another, not working
- Create permalink structure for one taxonomy archive per custom post type
- Adding %author% in custom post type URL structure?
- Custom post type’s get_permalink returns wrong url
- Custom post type permalink structure with the category also acting as an archive
- Prepend meta_value to permalink of post
- Pass parameter to custom post type single while keeping clean url
- Rewrite custom post type url’s adding meta box values
- Multiple parameters in a custom post type url rewrite
- URL rewrite and navigation structure for wordpress custom post type
- Removing CPT slug from URL results in 404 error for archive page
- Many to Many Taxonomies or rewrite rules?
- How to properly prefix blog post URL’s
- how to use two permalinks for one custom post type
- Adding a date archive to Custom Post Type
- Custom Post Type/ Taxonomy URL rewrite
- Bulk 301 redirect for custom post type
- Custom Permalink Tag breaks Pagination
- how to get archive urls with same origin for custom types and terms?
- Permalinks for Taxonomy and Custom Post Type
- Share parent path between Custom Post Types and Pages?
- multiple url slug for single custom post type
- Pretty URLs for Custom Post Type & Custom Taxonomy with Duplicate Slugs on WPML
- Custom Post Type and Custom Taxonomy Permalinks
- Pagination problem
- Custom Post Type Post have a Child `Page` Post Type Post
- Query var removed after rewrite
- Change Permalink Structure for Tag.php template
- Change custom post type slugs, with category/taxonomy before post type name
- Add archive slug to default post post type
- Custom Post type and permalink settings
- Rewrite post type slug only for child theme
- wp_list_categories() – current-cat class also inside posts?
- Adding custom post category slug in permalink causes 404 error for pages and posts
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- How can I make the slug of the taxonomy also the slug of the custom post
- Set a CPT slug as a base name for all the taxonomies
- Custom taxonomy rewrite with query var returns %2F in URL
- Remove slug in URL custom post type
- Versioned Custom Post Type (Not the same as revisions)
- cpt and page sharing same base permalink
- URL rewriting for CTP assigned entity
- Custom taxonomy returns 404
- Added Custom Post Type and the View Option Doesn’t Work
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Pretty URLs and custom post types
- Specific routing for CPT
- Lost of query parameter when using permalink
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- post_type_link Filter – Too Few Arguments
- WordPress Custom Post Type – Rewrite Query
- Dynamic CPT permalink structure based on ACF field value
- WordPress rewrite url
- url rewriting for custom post types
- Post type Permalink
- Add Custom Values to Permalinks Through Custom Fields and Posts
- Archive page for custom post type and custom taxonomy
- Rewrite rules for custom post type
- Combine 2 different custom post slugs into a single permalink?
- custom posts permalinks url rewriting
- Setting Parent Page to Post
- Add rewrite rule for custom post type single page
- Custom taxonomy terms as children of multiple custom post types
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- Custom Post Type & Taxonomies – Rewrite
- Display CPT taxonomies as an archive page
- Change CPT permalink to use the category
- CPTUI rewrite disable when no post in CPTUI has been found
- add_rewrite_rule wordpress ignoring url pattern, wp rewrite not working
- Rewrite of Custom Post Type doesn’t work with dynamic data
- Set archive of custom post type like ‘posts’ page in reading settings is set
- Custom URL for Custom Post Type & Custom Taxonomy Term
- Custom taxanomy and custom post type – pagination leads to 404
- Register post type getting error 404
- Flush rewrite rules when new cpt is registred
- Custom post url in search.php isn’t the correct rewrited url
- Custom WordPress URL
- One custom post type with two different url structure base on taxonomy term
- URL Rewrite Adjustment for Custom Post Type causes template to revert to index.php
- Custom Post Type – Rewrite slug [duplicate]
- Rewrite rules for using the same base slug for multiple content types
- add_rewrite_rule not working in Custom Post Type UI Plugin
- Looking for advice how to approach building a WordPress plug-in
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- 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