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.

I run a non-English blog. I love that WordPress has been translated to Spanish and currently I use the Spanish translated version of WordPress.

One thing that I'd really like to change is the URL structure for my blog. For example, instead of sitio.com/category/gatos, I'd like to change the URL to sitio.com/categoria/gatos. I know you can set the category base and tag base in Settings/Permalinks, but I'd like to know how to do this in code. Also, I want to translate search/ to busqueda/ and page/ to pagina/.

I want to translate all of these to Spanish.

  • category_base
  • author_base
  • pagination_base
  • feed_base
  • search_base
  • comments_base

I'd like to be able to make these this just within my own theme (that I've made from scratch), that way these changes could be more portable.

I've read the WordPress Codex for WP_Rewrite and have experimented with add_rewrite_rule, but I'm still stuck. Does anyone know where else I could look?

Update:

With this function, your search form can still use name="s", but the user will be redirect to the appropriate location on submit.

function redirectSearch()
{
    // Make sure you redirect to whatever your search_base is.
    if(!empty($_GET['s'])){
        wp_redirect(home_url('/busqueda/').urlencode(get_query_var('s')));
    }
}
add_action('template_redirect', 'redirectSearch');
share|improve this question

1 Answer 1

up vote 2 down vote accepted

This should cover everything:

function wpa_rewite_translate(){
    global $wp_rewrite;     
    $wp_rewrite->pagination_base = 'pagina';
    $wp_rewrite->author_base = 'autor';
    $wp_rewrite->comments_base = 'comentarios';
    $wp_rewrite->feed_base = 'alimentar';
    $wp_rewrite->search_base = 'busqueda';
    $wp_rewrite->set_category_base( 'categoria/' );
    $wp_rewrite->set_tag_base( 'etiqueta/' );
}
add_action( 'init', 'wpa_rewite_translate' );

Feel free to laugh at my translations, haha.

Also, to flush rewrite rules when your theme is activated, add this:

function wpa_flush_rewite(){
    flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'wpa_flush_rewite' );
share|improve this answer
    
Nice. Seems to be working well—except for one thing: if I type sitio.com/busqueda/gatos, then I get the right search page. But, if I use the search form, which uses s, then I get the non-permalink URL. –  piña Jun 24 '13 at 5:23
    
Ah, I found a way to recreate this effect by using wp_redirect to send me from /?s=hola to /busqueda/hola, but I'd like to avoid a redirect if possible. I wonder if there's some way I can edit my search form to send me to the right place. –  piña Jun 24 '13 at 5:55
    
That's the nature of web forms. You can use JavaScript to intercept the submit & formulate the URL, but I would stick with server-side. –  TheDeadMedic Jun 24 '13 at 6:37

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.