0

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');

1 Answer 1

2

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' );
3
  • 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.
    – 425nesp
    Commented Jun 24, 2013 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.
    – 425nesp
    Commented Jun 24, 2013 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. Commented Jun 24, 2013 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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