load_child_theme_textdomain doesn’t work in function.php

I have a child theme which is not localized. So I added this in function.php

add_action( 'after_setup_theme', 'my_child_theme_setup' );
function my_child_theme_setup() {
    load_child_theme_textdomain( 'mytheme', get_stylesheet_directory() . '/languages' );
}

It doesn’t work. I searched for hours and I read somebody advised putting this to the top of header.php

load_child_theme_textdomain( 'mytheme', get_stylesheet_directory() . '/languages' );

Suddenly it started working.

The problem is solved but I’m still curious why the legal way didn’t work. Any of you have an explanation?

1 Answer
1

First of all, mind your language please. If there are swear words in your code, please remove it before you post your code.

OK, to get to your question, there is nothing wrong with your code. It looks sound. Which parent theme are you using?

I have a child theme which is not localized

You should have a look at how your strings are localized. You should also have to look at your naming of your language files. Go and have a look at the codex. Always remember, use the codex as reference. You can also go and have a look at this tutorial to get some insight.

Apart from that you should be good to go

EDIT

I would like to keep the first part of this answer as reference for others. Your question had me puzzled, and then it hit me like lightning, I also missed the most obvious mistake, your template is named wrongly.

There is a huge difference between function.php and functions.php. WordPress automatically knows and uses functions.php as the main functions template in a theme. This template need not be called. On the other hand, function.php is just a template with no hierarchy. This template must be called in some way in your theme so that wordpress will know when and how to use that template.

So, on your question, just rename your function.php to functions.php

Leave a Comment