From 7067bf1fbda817da7fb948c63abc307678369776 Mon Sep 17 00:00:00 2001 From: Mark Fabrizio Date: Mon, 30 Mar 2026 10:06:56 -0400 Subject: [PATCH 1/2] feat: add ignore option for links in addLanguageToLinks function --- trunk/localizejs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/localizejs.js b/trunk/localizejs.js index 2f459b8..5d4aee3 100644 --- a/trunk/localizejs.js +++ b/trunk/localizejs.js @@ -147,7 +147,7 @@ function addLanguageToLinks() { const EXCLUDED_PATHS = ['wp-content', 'wp-admin']; // only use if subdirectories seo is set and plain permalinks aren't set, i.e. /es/my-page/ and not ?p=4&lang=es if (URL_OPTIONS == '1' && localize_conf.permalink_plain != '1') { - const links = document.querySelectorAll('a'); + const links = document.querySelectorAll('a:not([data-localize-ignore])'); links.forEach((link) => { if (link.href) { let url = new URL(link.href); From 5037f598e718940aa6c456fbe92ba2ba5e7b660b Mon Sep 17 00:00:00 2001 From: Mark Fabrizio Date: Mon, 30 Mar 2026 10:11:42 -0400 Subject: [PATCH 2/2] Add a data attribute to indicate that localize converted the link --- trunk/localizejs.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/trunk/localizejs.js b/trunk/localizejs.js index 5d4aee3..ee3e8e5 100644 --- a/trunk/localizejs.js +++ b/trunk/localizejs.js @@ -159,8 +159,10 @@ function addLanguageToLinks() { // so, we go ahead and remove the language if it exists. const lang = findLanguageInPath(url.pathname); if (lang) { + link.setAttribute('data-localize-original-url', link.href ); url.pathname = removeLanguageFromPath(url.pathname); link.href = url.href; + } return; } @@ -171,6 +173,7 @@ function addLanguageToLinks() { const docUrl = new URL(document.URL); const docLang = findLanguageInPath(docUrl.pathname); if (docLang) { + link.setAttribute('data-localize-original-url', link.href ); url.pathname = `/${docLang}${url.pathname}`; link.href = url.href; }