In WordPress, “—” and ” — ” become em-dashes (— —) and “–” becomes an en-dash (— #8212;). The sanitize_title_with_dashes() function doesn’t catch these.
That function uses the databased copy, but the title displayed to the user always goes through a texturize function. So if we replace en/em dashes on their way into the database, the net result will be the same and avoid these bad URL cases the titles are re-texturized.
add_action( 'title_save_pre', 'do_replace_dashes' );
function do_replace_dashes($string_to_clean) {
# The html entities (– and —) don’t actually work but I include them for kicks and giggles.
$string_to_clean = str_replace( array('—', '—', '–', '–', '‚', '„', '“', '”', '’', '‘', '…'), array(' -- ',' -- ', '--','--', ',', ',,', '"', '"', "'", "'", '...'), $string_to_clean );
return $string_to_clean;
}
Related Posts:
- How to Remove Slug From Database?
- How to make draft posts or posts in review accessible via full url / slug?
- Limiting the number of words or characters in the slug/permalink
- Make attachment pages require a base url
- Non latin post slug truncate
- Pre-populate Slug / Permalink with URL
- Suddenly new posts have the default permalink instead of the post name
- How to Custom Edit Post Title & Permalink Slug?
- Bulk append URL (add word to slug)
- Remove international characters from slug – Almost done – Bit help
- How to remove slug from front page?
- How do I structure my permalinks in WordPress?
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- How to create a standard WP Page that has the same url as an archive
- How to update permalink on the fly?
- Get Page URl when changing slug and permalink
- Can’t Remove Unnecessary Slug
- remove “index.php” from permalinks
- Get default permalink structure from pretty URL’s
- WordPress slug issue with non-latin characters
- Getting the Site URL Including the Front Base
- How to use relative links on my pages?
- Stop WordPress from reserving slugs for media items?
- Change slug on post creation
- WordPress Permalink changes to question mark (?) in URL
- Post type child of another post type
- Removing hierarchical pages in the permalink
- Is It A Good Idea To Change Author Slug (user_nicename field) Directly In MySQL DB?
- How can I force WordPress to redirect to canonical permalinks?
- When creating a WordPress page, a “-2” suffix is added to new pages’ permalinks
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- WordPress on a subdirectory of Laravel – WordPress pretty permalinks inner page shows laravel
- How to get url of a post from admin panel
- Remove subfolders from URL
- Replace WordPress %postname% suffix with %postid%?
- flexible rewrite ‘ramble’ URLs with WordPress
- How to get the post id from a permalink?
- How to Remove -14 from WordPress URL (Permalink)
- display URL or permalink instead of page title in dashboard
- Is using %postname% for permalinks really that bad for performance?
- Change permalink rule if category is called “uncategorized”
- Change author slug and functionality
- Get canonical link
- CSS not loaded when omitting www. part of URL
- How can I add a page’s ID to its permalink using WP_Rewrite?
- Setting up two separate blogs while using WordPress as a CMS
- Get page by path – honoring permalink settings (urls w/slashes)
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- Change blog segment of URL
- How to stop WordPress from removing & from URL?
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How to bulk edit image url in featured image and product description?
- Is there a link parameter that will show me all my published pages?
- wp not making CPT permalink / slugs unique
- Remove -2 from URL; no duplicate pages, no images, no pages in trash
- Edit page slug after save, cause 404 by linked pages
- WordPress keeps giving me the wrong permalink
- Relative v.s. absolute URLs: which ones should I use for cross-domain portability?
- Permalinks settings
- mod-rewrite exception? keep #hash in matching urls?
- Edit permalink for certain pages
- Two URLs of one post is available
- permalinks on title tag
- Can I change the URL structure for a CPT only?
- Gutenberg Editor: dynamically edit slug field based on ACF field
- How to redirect old permalinks from https://exmaple.com/category/post_id to https://exmaple.com/category/post_id.html
- New posts link to old posts (random)
- Make a post inaccessible without a unique ID in the URL
- Allow two posts (from different categories) to have the same slug
- A different permalink structure for different categories
- How to remove category name for only one category?
- How to prevent wordpress from lowering Capitalized letters
- Customize URL for specific tags archive
- Code snippet to add filter pre_post_link to change Media URL (post_type attachment permalink/slug)
- Rewrite rule not working, but only when parameter is text
- Why does one of my pages not have the option to edit the link?
- Giving specific category posts its own permalink structure returns 404
- Adding query string to multiple page urls in a WordPress function
- Post links broken after migration
- I have Akamai pointing to a WordPress installation with a different URL. Is there a way to make WordPress use this for link generation?
- How to allow different authors to use same post slug?
- Added a prefix in URL permalink structure but the old structure still working!
- Problem with permalinks
- Allowing slash in slug/permalinks
- Author permalink
- Force/Limit the post/page slug to accept only url friendly characters
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- Keep wordpress from modifying my permalinks
- Is there a way to remove the option to modify the Slug in post.php
- Issues with WordPress permalinks
- How to display post permalinks instead of pages?
- Why is there a # and other characters in URL for WordPress site?
- Update permalinks after domain change
- How to avoid duplicate Url for the home page
- Display a custom slug in URL depending on user variable
- Removing parent page in URL for one page
- UI does not show correct Slug after modified using save_post action
- Standard Htaccess directives disappear by themselves
- Creating WordPress pages with post name as slug
- Changing the URL slug causes redirecting to homepage, or showing 404 or missing lang_code issue