Search code examples
phpwordpresswordpress-themingthemeschild-theming

How to manually create a text-domain for a WordPress child theme?


I don't know how to manually add a text-domain to my child theme. I installed LocoTranslate to find out what the text-domain was, and it shows the same as the main theme.

This is a problem, but I need to add a file that has been made custom and it must call this child theme in various parts of the code, now it calls the main theme and this is the problem.

Searching I found [WordPress documentation on child themes,][1] but I must say that I don't know how to interpret it, my experience is not enough to know how to read this documentation.

I don't even keep looking and I can't find a site that describes how to do this by someone inexperienced.

Is there a document outlining the steps to create a child theme text-domain for beginners?


Solution

  • Go into the style.css file in your child theme. In the comment header, add a text domain field under the theme name field.

    /*
    Theme Name: My Child Theme
    Text Domain: mychildtheme
    */
    

    Then, go to your functions.php file in your child theme and add the following code.

    function mychildtheme_load_textdomain() {
      load_child_theme_textdomain( 'mychildtheme', get_stylesheet_directory() . '/languages' );
    }
    add_action( 'after_setup_theme', 'mychildtheme_load_textdomain' );
    

    Change 'mychildtheme' to the text domain you gave in your style.css file.