WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

some templates are chosen from WordPress based on slugs (e.g. category-{slug}.php).

Problem: How can I use the same template for an i18n'ed slug?

Example: I have a category-news.php and an english category with slug "news" and german category with slug "nachrichten". But of course "nachrichten" doesn't get category-news.php as a template. How can I i18n "nachrichten" so WordPress knows it means "news" before the template will be chosen internally?

share|improve this question
up vote 5 down vote accepted

Filter template_include:

add_filter( 'template_include', 'prefix_translate_template' );

function prefix_translate_template( $template )
    if ( 'category-' . __( 'news', 'your_textdomain' ) . '.php' === $template )
        return 'category-news.php';

    return $template;

But I think templates based on slugs are not a good idea in that case.

share|improve this answer
I didn't know the template_include filter. That seems to exactly solve my problem. Thank you very much. Any reasons why you wouldn't use slugs in this case? They seem to be very handy. – Pipo Apr 4 '13 at 9:20
You have to create a new rule for each category now. That's not elegant and probably slow and error prone. I wouldn't do that. A term meta field with a template selector in the back-end is probably better. – toscho Apr 4 '13 at 9:23
You are right, especially because we use a lot of categories and a lot of languages (not just english and german). I searched for something like a "template-chooser" (like implemented in pages) before, but couldn't found something useful. I thought WordPress doesn't support something like this outside of pages? – Pipo Apr 4 '13 at 9:26
There are workarounds for the missing term meta table on our site. :) You could also just use one category template and handle all the conditions in that file. – toscho Apr 4 '13 at 9:28

Your Answer


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.