Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_remove_emojis_from_slugs( $str ) {
- // Replace hexadecimal sequences with their corresponding Unicode characters
- $str = preg_replace_callback( '/x([0-9a-fA-F]{4,6})/i', function ( $matches ) {
- // Convert the hex to decimal, then to the corresponding Unicode character
- return mb_convert_encoding( pack( 'H*', $matches[1] ), 'UTF-8', 'UCS-4BE' );
- }, $str );
- // Remove remaining emojis using a regular expression
- $str = preg_replace( '/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F900}-\x{1F9FF}\x{1F1E0}-\x{1F1FF}]/u', '', $str );
- // Remove widow & duplicated slashes
- $clean = preg_replace( '|-+|', '-', $str );
- $clean = preg_replace( '/([-]*[\/]+[-]*)/', '/', $clean );
- $clean = preg_replace( '/([\/]+)/', '/', $clean );
- // Trim slashes, dashes and whitespaces
- return trim( $clean, " /-" );
- }
- add_filter('wp_unique_post_slug', 'pm_remove_emojis_from_slugs', 100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement