7

I am trying call load_plugin_textdomain once the plugins are loaded, however this does not happen. I do have a plugin activated, so shouldn't this fire?

add_action("plugins_loaded", "test_override");

function init_localization()
{
    echo "init_localization<br>";
    load_plugin_textdomain
    (
        TEXT_DOMAIN, 
        false, 
        LANGUAGE_DIR
    );
}

function test_override()
{
    echo "text_override<br>";
}

In another context, when calling add_action("init", "init_custom_post_types"), it works fine.

It may be of interest to know that I am working on a custom theme.

Thanks if you can provide any guidance, or ask if you need to know anything that could help you help me.

1
  • In additional to what Geert mentioned, why are you not using load_theme_textdomain() instead if you're working on a theme.
    – user23654
    Sep 2, 2013 at 15:31

1 Answer 1

20

Have a look at the wp-settings.php file. You’ll see that the plugins_loaded action is triggered before the theme is loaded. The first action available for themes to hook into is the after_setup_theme action.

3
  • Very cool, thanks for the guidance Geert and splashingpixels. I wasn't using those events or functions simply because I did not know of them and relied on another project. Now I do get that the action is called, however the translations are not applied. The translation items are for custom post type labels. Where should I look to have them picked up from the PO/MO?
    – jansensan
    Sep 2, 2013 at 16:32
  • Many plugins don’t hook their translations to the proper hook (like after_setup_theme or init). In that case you can’t override them from within your theme. Here’s how plugins should load translations properly. If the plugin author doesn’t update the code you could still go for a must-use-plugin workaround.
    – Geert
    Sep 2, 2013 at 18:30
  • Guess I wasn't clear. splashingpixels aligned me onto the right path: I'm actually building a custom theme, so I don't need info on plugins. I'm using add_action("after_setup_theme", "init_localization"), but the admin/CMS part of WP does not apply the strings from the PO/MO to the elements as expected. Any tips?
    – jansensan
    Sep 8, 2013 at 1:30

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.