When WordPress inserts a post, it runs the title through a filter called sanitize_title
to get the slug. By default there is a function called santize_title_with_dashes
attached to this filter with priority 10. This function simply strips out the |
. If it is surrounded by spaces those spaces will be converted to hyphens.
So your task is to run a filter on the same hook before (say, priority 9) the default one and replace the |
with -
before it gets stripped away. Like this:
add_filter( 'sanitize_title', function ( $title ) {
return str_replace( '|', '-', $title );
}, 9 );
Related Posts:
- Remove description from on Home
- Filter Widget Title Wrap
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- Alter only the page title, not the post titles within
- Changing document title only on a custom page template
- Filtering ‘the_title’ with option to return subhead?
- wp_title() empty on a static front page
- Can’t change the title tag with wp_title filter
- Setting title using wp_title filter
- Add a Span Around a Product Title in WooCommerce [closed]
- Wrap h1-h6 in a div
- How to add numeric slug for child page in WordPress 5.9?
- Variables in post title
- Is it possible to use multiple spaces in title?
- WP action/filter to modify title before header output and article output?
- Filter media upload attachment meta
- Use of comment_reply_link_args filter
- Filter page title (displayed in browser tab) of wp-login
- Strip $before & $after strings from a page title
- add_filter( ‘the_title’ gets through this if statement twice
- Filter Post Title without affecting screen-reader-text
- Modify WordPress Page Title ()
- How to filter page title for certain page?
- get_the_archive_title hook unwanted changes!
- Hide H1 Title using the_title filter
- Admin filter/error if post title is too long
- How to update permalink on the fly?
- Auto append text after the title?
- How to filter users on admin users page by custom meta field?
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Modify the post/entry wrapper markup in genesis childtheme [closed]
- post_row_actions filter is not working while update post using quick edit
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- get_the_excerpt() with fallback like the_excerpt()
- How to link current user to their author page through shortcodes
- Taxonomy Custom Column – ‘manage_{TAXONOMY}_custom_column’ filter only passing 2 arguments
- How to get list of all hooks of current theme / plugin?
- get_query stops working after post filter
- Can you use add_filter() inside other function?
- Add parent template name to body class filter when visiting subpage or single post
- is there a specific place where add_filter must be placed?
- add_filter() function misunderstanding
- How to make a widget expand wider than the column width when editing its settings in the admin
- Is there a wildcard/catchall filter hook?
- Apply the_content filter, but prevent other hooked actions
- Filter my args by the post 1st letter
- Adding Filter to Homepage only
- the_excerpt filter with an empty excerpt
- Add Defer Attributes to WordPress Scripts with consistent versioning
- Does auto_update_plugin Filter Work When Put In Theme’s functions.php File
- Remove CSS & JS files from WordPress Main Page For Increase Pagespeed?
- String regex match replace for role ‘contributor’ only
- In need of a content replace filter for posts in a specific wordpress category
- Can plugins that filter post contents work on posts from Word 2007?
- Inline Styles on all native blocks
- How to filter post content and force every link () made in blocks to return urldecode() with readable value?
- Changing WordPress core without hacking core
- Link to Shop-Filter with .current-menu-item
- Remove posts inside pre_get_posts using a custom query
- Remove / Hide Attachment Display Settings in Add Media popup / dialog
- how to customize rss feed tags using hooks?
- Woocommerce “added to cart” message on main(home) page
- Is it possible to apply filter to meta key value when querying posts?
- Add filter for specific post type only
- apply_filters with multiple args and multiple add_filter
- Avoid user registrations with specific email provider
- Should I remove_filter in order to replace a filter?
- How can I specify the post status of an untrashed post?
- Conflict calling an add_filter() twice
- Filter for author list in gutenberg core editor
- Rewrite rule and display of post
- Passing variable from child theme function to parent theme filter
- paginate_links() Change the order of links
- Filter / add_action to upgrade.php page
- Add Filter – Pass Variable (PHP < 5.3)
- How to disable a wp filter in a certain admin panel page
- Why does admin_body_class not work?
- post_orderby filter breaks function
- Problem width wp_insert_post_data and Gutenberg block editor
- Counting a WP_Post Object value in an arary, using a filter?
- add_filter doesn’t return false?
- How to track a particular page in order to address the loading speed issue
- List all categories that have results in a query
- how to overwrite next_post_link
- Displaying posts on a page that have been assigned a value in a database
- Replace Text with hyperlinks
- Print url to default featured image
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- Adding user filter – Not updating data in URL
- How to check which submission button was clicked?
- filter wptexturize doesn’t work on old posts titles
- remove_action conditionally for Custom Post Type – not working
- wp_get_attachment_link filter not working
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- Getting entry ID from frm_email_message filter in formidable
- Is there a hook or filter that adds a button to the left of the search box?
- How to put title slug into content when create a new post?
- Filter and manipulate the get_current_user() function
- Limit total tags in the_content