Remove Hyphens in Two-Worded Slugs for SEOPress

Recommendation

Learn why I switched to WPCodeBox for managing code snippets for myself and for my clients.

Instructions

Snippet Type: PHP

  1. Copy the snippet.
  2. Add the snippet using WPCodeBox.
  3. Follow any customization notes provided.
  4. Save the snippet.
  5. Enable the snippet.
  6. Test.

Snippet

The Remove Hyphens in Two-Worded Slugs for SEOPress code snippet fixes a slug formatting issue within WordPress websites, as described below.

For example, let’s say you have an element named “Service Providers”. 

When using SEOPress (and perhaps other SEO plugins), the slug would appear as “service–providers”, rather than “service-providers”.

				
					// REMOVE HYPHENS IN TWO-WORDED SLUGS FOR SEOPRESS
add_filter("seopress_social_og_title", function ($seopress_social_og_title) {
  return str_replace("-", " ", $seopress_social_og_title);
});

add_filter("seopress_titles_title", function ($seopress_titles_title_template) {
  return str_replace("-", " ", $seopress_titles_title_template);
});