You could use an anonymous function and pass the variable to it with use
.
$updatedLanguage = $languageArray[$pageLanguage] ?? '';
if ( $updatedLanguage ) {
add_filter('locale', function($locale) use ($updatedLanguage) {
return $updatedLanguage;
});
}
If you’re changing the locale at runtime, then you may want to look here Change locale manually at runtime?, where it is noted that the change could have a performance impact. Also, you may need to do the change early enough in the WP loading sequence so that the correct translation file gets loaded – if it something that you need.
Related Posts:
- How to correctly add Javascript in functions.php
- Genesis – Customize search form
- Set media upload attachment link to none and hide it in WP v3.5
- How to set custom cookies before output
- How to use wp_insert_user on WordPress Multisite?
- Why does this echo values in the wrong order?
- On this day PHP code
- Print out WordPress user ID – two sites with same code but different output
- How to add default images into theme customizer image control?
- Woocommerce: How to override core functions in functions.php?
- Add custom HTML to posts page
- Successful or Error Message after running mysql code in functions.php
- How do I get a list of popular posts by views?
- sidebar isn’t showing, what’s wrong w/ this code?
- Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
- How to run PHP code in Text Widget with no plugin in WP 4.4
- How to only show page id as body class?
- Insert array data on plugin activation
- Auto crop images in WordPress
- Adding Default Settings to Theme My Login plugin
- How to add values to media “whitelist_options” in wp-admin/options.php template?
- Increase returned number/pages on pagination
- Remove wp_admin_bar fail on wordpress 4.0
- How to use an associative array in post__in with WP_Query?
- Extract 1st word of blogname/insert in middle of new string
- Can you run WordPress on a MarketLive/Java EE server?
- function to assign user role based on a field from usermeta
- Hiding div based on user role
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- filter default query to show just selected level of child pages in wordpress
- Set meta field to publish date + 2 weeks
- Exclude posts based on meta value
- wp_enqueue_script seperately for each shortcode
- What esc_ to use to validate this?
- How to display product category in custom developed theme?
- Refresh table data with Ajax
- How i can obtain all the post meta for a specific post as an array?
- Filtering a function’ output for a new continued function
- Delete taxonomy and delete all post related it
- Styling the second sidebar
- first instantiated SimplePie object cosumes 5mb?
- Theme not calling Jquery properly
- Creating Database Table vs. Adding MetaData to Post & User
- How to set a template with wp_insert_post
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- WordPress redirect redirecting too many times or not at all
- How to end a while loop when used in a fetch assoc function [closed]
- Why my loop isn’t working? [closed]
- How to use AJAX to call php page with parameter
- Menu Custom Data Attributes
- Pass return-path additional parameter in wp_mail
- How to get image from url from the database?
- WordPress meta_query >= &
- Change header on pages displaying taxonomy items
- How to override a plugins script
- Comparing Dates from custom field
- Prevent Company Name From Translating
- Displaying Slider in Front Page (home) using Customizr Theme
- Usage of var keyword in the core
- Taxonomy term description with style, only if the description exists?
- Ajax URLs without #!, how to prevent falling into single.php on load or reload?
- PHP displaying wrong custom taxonomy images
- Slow site initial load time
- Page load timer?
- How to sort posts by active category in WordPress?
- wordprees multi-site in user panel add filter
- WordPress custom php script to match standard page layout
- copy fields value to another field
- Get parent category name when only child category is applied to a product
- Updated Php version from 5.4 to 7.2 and getting “PHP installation missing the MySQL extension needed by WordPress”
- Before & After Content – After Content directly below Before Content when using require_once
- Get Child of Child Pages in custom Menu
- Latest posts feed with a specific post always first
- Top Authors list by highest post views with Ajax pagination
- WordPress Post undefined error with Post Date (New to Wordpres Dev)
- From php web to wordpress conversion, href changes only in URL
- How can i put php code on the wordpress page?
- What’s the correct offset value for order ASC?
- can’t grab PHP $_POST variable
- Setting at job with shortcode not working
- How to solve 404 permalink errors on nginx server
- Ajax Load more CPT via shortcode
- Loop 1 user randomly
- Order by in foreach
- Sort by multiple options in custom field
- Query seems to be duplicated
- two sites, same code, different presentation
- WPMU schedule doesn’t execute actions
- ISOTOPE – Missing/Invalid Arguement Get Terms
- doubled content
- Adding if statement to content for homepage
- Add Condition if WPBakery Page Builder Used on Page or Not
- Data inserted in database, but ajax calls error function
- how to import contacts from php to wordpress
- How to add active class dynamically
- I’m not able to get access $wpdb in my php file in wordpress
- Submit cf7 form to cfdb as pdf/BLOB [closed]
- How can add alt tag in following code. Image are showing dynamic in wordpress
- how to create twitter card without plugin in wordpress website?
- How to use phpspreadsheet reader with $wpdb