By default WordPress only loads translations according to the user’s language when they’re viewing admin pages.
You can see that in the code for the load_theme_textdomain function:
$locale = apply_filters( 'theme_locale',
is_admin() ? get_user_locale() : get_locale(),
// ^^^^^^^^
$domain );
So your code is fine if you want to override that behaviour for the front end of your site.
Is it conventional? Well, this is what filters are for. However, I’d say this isn’t normally done unless the language of the actual content is also changing.
Related Posts:
- How to create .pot files with POedit?
- Enqueue Stylesheets After Theme’s “rtl.css”
- Caching and Versioning for rtl.css
- Use __($str) and _e($str) to translate strings with HTML
- What is the purpose of an extra file for translation?
- Translated strings not appearing – what am I missing?
- How to change i18n/l10n of #reply-title? (Old title: Comment reply link not working)
- Internationalization and functions that use it
- Theme translation not applying
- 2 localizations inside a WordPress theme
- Should I change text-domain of TGM library inside theme?
- Change locale by detecting viewer’s browser language setting and let them choose prefered language after
- Single translation for many locales
- Does the textdomain have to be the theme’s name?
- Do I need to include a textdomain if my theme doesn’t support translation?
- using Options Framework – can “theme-textdomain” domain be changed?
- Translate a theme with a PO file
- how to unlocalize theme/plugin?
- Menu names not getting translated
- How to generate a rtl.css file for themes?
- Enqueue Stylesheets After Theme’s “rtl.css”
- Display Today’s date outside the loop?
- What are these variables and where are they documented?
- How to use esc_attr__() function properly to translate a variable that contains string?
- wp_redirect() – headers already sent
- The the_post_thumbnail without srcset?
- after_setup_theme always runs
- How to add default images for custom backgrounds?
- Custom Theme: The active theme is broken. Reverting to the default theme
- comment_form() generates the wrong action url
- Customize comment list markup
- Have WP Theme update from Git Repository
- A two column loop with one lead post
- new theme permissions don’t allow me to edit
- Getting Permalink within the loop
- Can a child theme based on Starker theme be released as free to use theme for public use?
- Changing order title and featured image in blog post (Astra theme)
- wordpress custom theme import and export options for sample data [closed]
- How to hook CSS file according to theme selection in the customizer section
- Link won’t show using the_permalink();
- How exactly *does* unit testing work for themes?
- qTranslate with my own theme and settings
- Make logo dynamic in wordpress
- Do i need to keep all the default WP templates files in a theme?
- Create a new page in WordPress theme
- where to split off footer.php
- How to show user online status on their posts?
- What is the correct way of getting parent styles from child theme?
- How to display all subpages and short by year
- how to setup custom content structures
- WordPress Filtering Custom Post Type by Metadata and Search Heirachy
- How to Call pages from a Options Panel
- Nested comments in WordPress theme
- Is there a list of all display functions for templates? [closed]
- Featured Image meta box not showing up
- Why does WordPress append numbers to page slugs sometimes? How to reliably style based on page
- filemtime(): stat failed warning within a child theme
- What are the hooks in WordPress theme development?
- WordPress dummy data for theme design
- Custom theme: How to call archive-post.php for viewing blog posts
- Dynamic Post Thumbnail →
- How to allow certain PHP functions when using sanitize_callback in the word press customizer
- How to allow users to create their own website within my domain? [closed]
- Problem escaping text which contains html markups
- Different text on different sites in a multisite setup
- Editing my theme to try to place the default header at the top of the page breaks the rest of the page content
- WordPress creating images if uploaded image is greater than 960px on one side?
- Create theme for mobile phones and tablets only?
- How to create a WP theme that use BootStrap? [closed]
- Alternatives to handle customizer settings
- Changing sidebar.php and footer.php depending on URL
- Seeting Active Nav for Bootstrap in WordPress
- Change default rel attributes for Image Block & Button Block
- ACF get_sub_field ALT TAG in the repeater doesn’t show
- Best way to implement bootstrap after loading
- Why front-page.php doesn’t show content of file instead shows loop
- How to Detect “Your homepage displays” setting in wordpress
- Why does wp_customizer default values do not apply when theme is installed for the first time?
- Building a custom menu or use a plugin?
- How Do I Create a WordPress Demo Site with Limited Admin Access
- Woocommerce REST API for my account & checkout process
- how to edit woocommerce checkout page
- Necessary css classes to be included in theme stylesheet
- Setting a fluid content width
- get_the_excerpt() removes all p tags in page!
- jQuery conflict in WordPress, works fine in HTML
- Including some variables in function.php and echo them is several place of theme is not working
- How to migrate the menu from the site on my own theme in WordPress?
- Why is including all your files within a theme folder important?
- Change default options on attachment page
- FitVid not working for iframes on particular theme install
- Make theme editor to show all theme’s files
- How do I change the tagline input to textarea?
- can’t add EVENT LISTENER to a element
- add_action works outside condition but not inside it
- Bootstrap isn’t called into my WordPress theme
- Jquery Ui Tabs not working
- Adding a new layout for genesis
- How to automatically set a Template Page Name next to a page in menu screen such as WooCommerce pages, front page, or posts page in wordpress?
- Remove nonindex meta tag