Child Theme Language File

  • Dan
    Newbie 14 points
    March 30, 2020 at 9:36 pm

    I’m using a child theme under DT9 and I can’t get it to use the language files in /childtheme/languages/

    This is in my child theme functions.php

    	function __construct(){ 	
    		load_child_theme_textdomain( "childtheme_ChildishTheme", get_stylesheet_directory() . "/languages" );	

    If I load the and en_US.po file into the parent theme language directory it works fine.

    I am not creating a whole translation, just changing a few phrases here and there.

    Any ideas for me?

  • Adnan
    Elite Member 543 points
    March 31, 2020 at 8:56 am

    @Dan: I think you should use the parent theme slug instead of child theme slug: “childtheme_ChildishTheme”

    Check here:

    Alternatively, you can use loco translate plugin.

  • Dan
    Newbie 14 points
    March 31, 2020 at 2:45 pm

    Thanks Adnan!

    I tried using Loco Translate but I couldn’t get it to work. After many hours and many configurations I gave up and went for the manual method.

    For some reason my functions.php file had my child theme slug in it. I was not sure which slug should go there (thanks for pointing me to the WP reference). However, I had the hardest time figuring out definitively what the parent theme slug was. I tried, DT9, dt9, etc, etc, Finally just tried premiumpress and it worked!!.

    I feel there must be a definitive way to obtain the parent slug name. I searched quite a bit for an answer to this with no luck.

    Thanks again for your help!

  • Adnan
    Elite Member 543 points
    March 31, 2020 at 5:30 pm

    You are welcome. I am glad it’s fixed.

  • Dan
    Newbie 14 points
    March 31, 2020 at 7:40 pm

    Just wanted to post clarification on the parent slug in case anyone else has this issue. From what I have read, the parent slug and the parent theme directory name should usually be the same thing.
    However, what needs to be in the child themes functions.php code below is the “text domain” which can obviously be different from the slug.

    load_child_theme_textdomain( "text domain here", get_stylesheet_directory() . "/languages" );

    There doesn’t seem to be any easy sure fire way to get the text domain that I can find but an easy work around is to install Loco Translate and click on “Themes” in the admin sub menu. This will display a table listing among other things the text domain for each theme you have installed, including child themes.

    I imagine there is a WordPress function one could use to retrieve the text domains for themes or somewhere one could look but this is the best I could come up with.

Viewing 5 posts - 1 through 5 (of 5 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes