2

Which is the best/recommended way to hook load_plugin_textdomain within - plugins_loaded or init? and what are drawbacks using either.

2

Load translation files as late as possible for your plugin's use-case. This allows other plugins as much time as possible to fully initialise.

Why should you care about other plugins? Because they may be involved in the localisation process too. For example, changing the site language or filtering translation file paths. They can't do those things if you beat them to it.

From your two examples: plugins_loaded fires first, so init is the better of the two in most cases. However, it still runs the risk that your init code fires before another plugin's init code, so set a low priority in your add_action call. (larger number = lower priority).

If your translations are needed earlier then you'll have to load them earlier. However, if you need them earlier than init then your whole setup might be firing too early.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.