Skip to content

Instantly share code, notes, and snippets.

@lynt-smitka
Last active April 1, 2020 10:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lynt-smitka/d1fc6aa56b2ed6a35f2c0d5c7a68a0dd to your computer and use it in GitHub Desktop.
Save lynt-smitka/d1fc6aa56b2ed6a35f2c0d5c7a68a0dd to your computer and use it in GitHub Desktop.
<?php
function lynt_is_en() {
$path_parts = explode('/', $_SERVER['REQUEST_URI']);
if (isset($path_parts[1]) && $path_parts[1] === 'en') {
return true;
}
return false;
}
function lynt_set_locale($locale) {
if (lynt_is_en()) {
$locale = 'en_US';
}
return $locale;
}
function lynt_register_en_sidebars() {
register_sidebar(array(
'name' => __('Footer 1 EN', 'lynt_theme'),
'id' => 'footer-1-en'
));
}
function lynt_switch_sidebars($widgets) {
$original = 'footer-1';
$new = 'footer-1-en';
if (lynt_is_en() && isset($widgets[$original]) && isset($widgets[$new])){
$widgets[$original] = $widgets[$new];
}
return $widgets;
}
function lynt_switch_menus($args) {
$new_id = 4;
if (lynt_is_en() && $args['theme_location'] === 'primary') {
$args['menu'] = $new_id;
}
return $args;
}
add_action('locale', 'lynt_set_locale');
add_action('widgets_init', 'lynt_register_en_sidebars');
add_filter('sidebars_widgets', 'lynt_switch_sidebars');
add_filter('wp_nav_menu_args', 'lynt_switch_menus');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment