To keep legacy entries on a blog hosted on TypePad on sync with a new WordPress installation…

How do I map this permalink with accented letters:

domain.com/no-es-fácil-alejarse-de-la-política

to this clean WP permalink without accented letter:

domain.com/no-es-facil-alejarse-de-la-politica

What is the best way to accomplish this?

2 Answers
2

The best way to accomplish this is remove the default sanitize_title filter and replace it with yours, which will encode those characters properly. Here is an implementation of using accents in permalinks.

Example:

remove_filter( 'sanitize_title', 'sanitize_title_with_dashes');
add_filter( 'sanitize_title', 'restore_raw_title', 9, 3 );
function sweURLtoCHAR($text)
{
  $url=array(
    "%C3%81","%C3%A1",
    "%C3%8D","%C3%AD"
  );
  $char=array(
     "Á","á",
     "Í","í"
  );

  $str = str_replace($char,$url,$text);
  $str_new = str_replace(" ", "", $str);
  return strtolower($str_new);
}
function restore_raw_title( $title, $raw_title, $context ) {
  if ( $context == 'save' )
   return sweURLtoCHAR($raw_title);
  else {
   $title_new = str_replace(" ", "", $title);
   return strtolower($title_new);
  }
}

You can find the characters and their utf8 hex here and build an array with the accented characters you need.

Leave a Reply

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