One would expect there to be a direct filter for this, but the only one I see requires you to completely take over the creation of a proper slug, which gets pretty involved. However, the process that removes the apostrophe is filtered so that plugin devs are able to add additional sanitation. You can add a preemptive callback that replaces apostrophes with hyphens before the usual sanitation function gets a chance to strip it out. Hook the “sanitize_title” filter with a priority argument less than 10 to do so.
Would you have a draft code to take as an example? I don’t know where to start…
Something like this (in functions.php, untested ):
add_action('sanitize_title', function( $title, $raw, $context ){
if ('save' == $context ) {
$title = str_replace("'", '-', $title );
}
return $title;
}, 5, 3 );
A further improvement would be to only alter apostrophes bounded by letters and not single quotes before or after a space or other punctuation. Alter “L’alba” but not “For example ‘foobar’.”
Many thanks. It works perfectly!