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:
- Remove slug from custom post type post URLs
- Change “Enter Title Here” help text on a custom post type
- Add .html (dot HTML) extension to custom post types
- Possible to change the URL for the regular post type without affecting the URL of other custom post types?
- Use a separate upload folder for custom post attachment upload
- 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 give a CPT (custom post type) a date based url
- How to correctly get post type in a the_title filter
- How to hook into the CPT’s title placeholder?
- title_save_pre on post publish
- Set Custom Post Type title to the Post’s Date
- Change title in head on Archive page
- How To Set Custom Post Type Title Without Supports
- Custom Taxonomies Terms as Post Title for Custom Post Types upon Publishing
- URL for custom post type
- Custom Post Type Archive URL takes over page URL
- Set post title from two meta fields
- WordPress Custom Post Type Category Page
- 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
- Change the url of Projects in Divi Theme
- Creating multiple page URL without creating the pages in WordPress
- Custom Post Type with Custom Title
- 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]
- Custom Post Types: Custom columns with Title submenu?
- Posts created in a Custom Post Type are lost if published without a title
- Rewrite Custom Post Type URL slug
- What is the impact if i ignore title and content in my custom post types CPT?
- Get a permalink structure of /%posttype%/%category%/%postname%
- How to filter out post type meta?
- CPT posts listed by category with custom rewrite URL, please help!
- Updating post title using wp_update_post
- 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
- How to use the Display Name as the post title in a custom post type?
- Bizarre Permalinks Issue: 404 Errors Everywhere
- How to detect filter in URL in Category page?
- Add acf field in title (admin table)
- Custom Post type and permalink settings
- How can I run this code once so that my generated post title doesn’t keep changing on publish/update?
- Custom Post Types, URL rewrite on multiple CPTs
- Get Taxonomy Term Title by it’s URL
- can I chage url for register_post_type
- How to add a post slug to a url?
- URLs for child terms
- Front custom edit post page for each post
- Set a maxlength for the title input in a custom post type
- How to build custom route by adding taxonomies to URL ? ex: www.demo.com/communities/palo-alto/
- Remove the parent slug in a CPT URL
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- Rewrite Question Mark in Post Template to Make it Pretty URL
- Changing the search url according to language
- WordPress randomly shows 404 errors
- 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
- Category slug not showing for Custom Post Type
- Customize category URL
- Remove custom taxonomy ‘post-type’ from post URL
- Cannot get query var ‘post_type’ to work
- Why are my wp urls showing page not found?
- Sorting custom post types by taxonomy (So close)
- 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
- WordPress pagination URL
- img src not working correctly in custom post type
- Links in archive not including taxonomy parameter
- Custom post type split title, setup permalink accordingly
- 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]
- Custom post type with custom taxonomies structure url not working archive of CPT
- Is it possible to use a post name in a custom post slug?
- Rewrite rule taxonomy url with different values in one function
- Change post-name when inserting new Post if Specific Category is selected in WP
- How do I get parameters from the URL?
- Custom Post type with a sub-URL under another Custom Post Type
- How to Display Content from Search URLs on Permanent URLs in WordPress?
- How to Dynamically Filter Custom Post Types by Taxonomy Based on URL in Elementor Pro and ACF?
- How to correctly edit permalink structures for both default and custom posts/taxonomies?