Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Apr 28 '12 at 19:00

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
Can you provide a code example here? –  Brian Fegter Oct 21 '12 at 23:02
1  
Just edited and added an example code :) –  aWordpress Oct 21 '12 at 23:47
    
Why do you need to change out sanitize_title? According to codex.wordpress.org/Function_Reference/sanitize_title "and (in a 'save' context) accents are removed (accented characters are replaced with non-accented equivalents)". So, if you can simply run sanitize_title with save contwext you get the slug without accents. There is also a wordpress function remove_accents (codex.wordpress.org/Function_Reference/remove_accents) –  Adam May 15 '13 at 12:03
    
Worked like a charm, but to make it work I changed sanitize_title_with_dashes with sanitize_title to write the url, not just the permalink slug. Thanks. –  Juan Jul 20 '13 at 12:49

You could make a redirection with .htacces or perhaps try out the wordpress plugin redirection.

share|improve this answer
    
Thanks, but what would be the rewrite rule to be used on the .htaccess file? I'm redirecting thousands of posts. –  Juan Apr 29 '12 at 12:59
    
No idea, i'm not an expert on the rewrite-rules myself. You could check out the docs of the apache manual. –  Zombaya Apr 29 '12 at 23:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.