you want to sanitize the title or the post_name (slug)?
if you want to filter post_name you can check wp_unique_post_slug
filter or you can use the wp_insert_post_data
filter to filter all post data before insert or update in db.
add_filter( "wp_unique_post_slug", "url_sanitizer", 10, 4 );
function url_sanitizer( $slug, $post_ID, $post_status, $post_type ) {
// get original title by $post_ID if needed eg. get_the_title($post_ID)
if( $post_type == "your_cpt" ) {
$slug= str_replace( ' ', '_', $slug);
$slug= str_replace( '-', '_', $slug);
}
return $slug;
}
Reference:
wp_unique_post_slug
documented in wp-includes/post.php Line No. 3790
wp_insert_post_data
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data
Related Posts:
- Change “Enter Title Here” help text on a custom post type
- Possible to change the URL for the regular post type without affecting the URL of other custom post types?
- How do I get a post (page or CPT) ID from a title or slug?
- Limit the word count in the post title
- Is there a way to override the tag specified in header.php?
- How to correctly get post type in a the_title filter
- Set Custom Post Type title to the Post’s Date
- How To Set Custom Post Type Title Without Supports
- Custom Post Type Archive URL takes over page URL
- How I check if the same post slug has not been used before publishing?
- How to Add Pages Under Custom Post Type URL Structure?
- Best Way to Leverage Custom Post Type Related Content and Consider SEO
- How to have a custom URL structure for a custom post type?
- Pagination throws 404
- Creating multiple page URL without creating the pages in WordPress
- WordPress custom post type url change
- Setting a title on a Custom Post Type that doesn’t support titles
- remove post-name from title in custom post type
- Using a Custom Field instead of original title field but only for Custom Post Type
- Search Post Title Only [duplicate]
- dynamically update permalink and title with the values of custom fileds
- get_page_by_title() not returning anything [closed]
- Rewrite Custom Post Type URL slug
- CPT posts listed by category with custom rewrite URL, please help!
- How do I get the permalink structure to work like this?
- Using several custom fields as custom post title
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- URI returns a post when it should return a 404
- Query string parameters from custom fields, inconsistent results
- Query var removed after rewrite
- Bizarre Permalinks Issue: 404 Errors Everywhere
- Add acf field in title (admin table)
- Custom Post type and permalink settings
- Get Taxonomy Term Title by it’s URL
- How to add a post slug to a url?
- URLs for child terms
- Changing the search url according to language
- Custom title set on quick edit
- non-hierarchical post type with hierarchical url structure
- Custom Postype specific changes in admin panel
- Custom Meta Title for Custom Post Type
- Taxonomy in URL
- Best structure / rewrite rules to achieve the following url
- How to set the seo title tag on a page by page basis?
- Add the post type to the title of the page
- CPT category hierarchy
- Create Custom Post Type as page
- Custom meta Title for custom post type archive from page
- How does: /index.php?post_type=event&event-date=2011-07-25 work? What if it doesn’t work?
- Address as a content type post
- How to create connection among state, city, store and store number based on URL
- custom endpoints on Custom Post Type return 404 page not found
- Custom Post Type Category URL
- link featured image to external link
- How to add page under a custom post type?
- Changing custom post type URL issue
- Custom Post Type URL Rewrite’s
- Post/Custom Post Type URL Access
- Add the custom post term to the custom post title
- Auto Generate Post Title from 2 Custom Fields
- returning the currect URL for nested posts
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- URL for archive of custom post type with 2 taxonomy terms
- Subpages URLs for Custom Post Type
- Query custom post type and custom field by URL parameters
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Turning archive templates to a page template maintaining the slug
- CPT – Custom Text fields point to new url permalinks
- filter the title changed also the page titles
- How to display a custom post as a page (but unedited)?
- WordPress Custom post type slug rewrite
- How to manage a custom post type archive as a page?
- How to manage a custom post type archive as a page?
- Error [Column ‘post_title’ cannot be null] when title is disabled for Custom post type
- Custom Post – additional param in the custom post URL goes to error page
- Single Post (CPT) in two pages – Normal and Extended
- What am I doing wrong with my taxonomy?
- Do not output category and tag URLs
- Force WordPress to only match URL in category
- Custom post type clean url
- Custom post type with parent page? Possible?
- Set the Title of a Custom Post Type by code as Author’s Username
- Custom url for custom post types
- Stop Custom post type from being searched via URL
- Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?
- remove custom post type ulr
- Customize category URL
- Remove custom taxonomy ‘post-type’ from post URL
- Cannot get query var ‘post_type’ to work
- Register a title automatically with a relationship field
- Removing custom post type name in single article URLs
- create gallery page for specific post id
- Tags and Taxonomy links not working for Custom Post Types
- Creating additional page with own URL for each custom post
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Hide custom post type slug url from search engine [closed]
- Is it possible to use a post name in a custom post slug?
- Rewrite rule taxonomy url with different values in one function
- How do I get parameters from the URL?