CPT Post Title Permalink: Replace “@” (or all special characters) with dash “-” instead of just removing

I have Custom Post Type “Email”, where the Post Title is always going to be an email address, ie: example@domain.com

The problem I am having is the “@” is being removed in the permalink: ../exampledomain-com

I would like it to save as: ../example-domain-com

Replacing the “@” with a “-“

I tried the following from here, but as someone more knowledgeable will quickly see, it doesn’t apply to the permalink:

function at_to_dash($title) {
return str_replace(‘@’, ‘-‘, $title);
}
add_filter(‘sanitize_title’, ‘at_to_dash’);

Read more here:: CPT Post Title Permalink: Replace “@” (or all special characters) with dash “-” instead of just removing

Leave a Reply

Your email address will not be published. Required fields are marked *