-
-
Save tommcfarlin/035b213bd632d2ab9fc4a79acffa1342 to your computer and use it in GitHub Desktop.
[WordPress] Remove Special Characters from Permalinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('wp_insert_post_data', __NAMESPACE__ . 'processPermalink'); | |
/** | |
* Processes the permalink so we can remove any characters that may cause a problem when communicating | |
* with the API. | |
* | |
* @param array $data The array of information about the post. | |
* @return array $data The data without the malformed information in the post name for the URL. | |
*/ | |
public function processPermalink($data) | |
{ | |
if (!in_array($data['post_status'], array('draft', 'pending', 'auto-draft'))) { | |
$data['post_name'] = | |
preg_replace( | |
'/(%ef%b8%8f|™|®|©|™|®|©|™|®|©)/', | |
'', | |
$data['post_name'] | |
); | |
} | |
return $data; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment