Skip to content

Commit

Permalink
feat: Add language value to local JS variables if WPML installed.
Browse files Browse the repository at this point in the history
  • Loading branch information
danimalweb committed Jan 9, 2024
1 parent 8a915f1 commit 4c7a074
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions inc/lib/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,20 @@ function localize_scripts()
}
}

wp_localize_script('tofino', 'tofinoJS', [
$data = [
'ajaxUrl' => admin_url('admin-ajax.php'),
'nextNonce' => wp_create_nonce('next_nonce'),
'cookieExpires' => isset($expires) ? $expires : null,
'themeUrl' => get_template_directory_uri(),
'siteURL' => site_url(),
]);
];

// Add WPML language code to JS
if (function_exists('icl_object_id')) {
$data['language'] = apply_filters('wpml_current_language', null);
}

wp_localize_script('tofino', 'tofinoJS', $data);
}
}
add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\localize_scripts');
Expand Down

0 comments on commit 4c7a074

Please sign in to comment.