Skip to content

Instantly share code, notes, and snippets.

@yehudaTiram
Created June 18, 2023 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yehudaTiram/e362c6bfd22958fdd244a9861800ff75 to your computer and use it in GitHub Desktop.
Save yehudaTiram/e362c6bfd22958fdd244a9861800ff75 to your computer and use it in GitHub Desktop.
/*
* Tired of typing a search term in my cooking blog just to find that I typed in Latin keys instead of Hebrew. See here https://yehuda-tiram.com/
* This code will replace every Latin character in WordPress search textbox with its Hebrew equivalent.
* The const hash can be changed to any language as needed.
* The search textbox element document.getElementsByName('s') can be changed to anything else.
*/
add_action('wp_footer', 'atr_latin_to_hebrew_key');
function atr_latin_to_hebrew_key()
{
?>
<script>
window.addEventListener('load', (event) => {
const hash = {
'a': 'ש',
'b': 'נ',
'c': 'ב',
'd': 'ג',
'e': 'ק',
'f': 'כ',
'g': 'ע',
'h': 'י',
'i': 'ן',
'j': 'ח',
'k': 'ל',
'l': 'ך',
'm': 'צ',
'.': 'ץ',
'n': 'מ',
'o': 'ם',
'p': 'פ',
';': 'ף',
'q': '/',
'r': 'ר',
's': 'ד',
't': 'א',
'u': 'ו',
'v': 'ה',
'w': '\'',
'x': 'ס',
'y': 'ט',
'z': 'ז',
',': 'ת',
};
document.addEventListener('keyup', function(event) {
const key = event.key;
const hebrewCharacter = hash[key];
if (hebrewCharacter) {
const currentValue = document.getElementsByName('s')[0].value;
document.getElementsByName('s')[0].value = currentValue.replaceAll(key, hebrewCharacter);
}
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment