why my HTML code in header does not work?
-
Hi,
I have a small html/js code for button, and I am going to use it as a language switcher in my website:
<button id="enfa-button" style="cursor: pointer; padding: 10px;">fa</button> <script type="text/javascript"> const button = document.getElementById('enfa-button'); button.addEventListener('click' , enfa); let enurl = window.location.href; function enfa(){ let faurl = enurl.replace("example.com", "example.com/fa"); open(faurl, '_self'); } </script>You may change “example.com” to part/whole of url where you are testing this code and “example.com/fa” with your desired url.
I use this code in Appearance->Customize->Header->HTML
and it only work when I am logged in as admin, but when I am not logged in it does not work.
There is a plugin you might know named WPCode, which allows to create shortcode from code snippet.
I created a bank snippet in WPCode snippet plugin, and inserted the above code into this blank snippet (code type: HTML snippet) and activate it, and inserted its shortcode in the same place (Appearance->Customize->Header->HTML)
and again it does not work (click not doing anything),https://ibb.co/VvSMtjr
https://ibb.co/2d4p8JVhowever when I inserted this shortcode into a text inside posts or pages, it works fine.
https://ibb.co/MskB4VK
https://ibb.co/whRVtNWPlease let me know where does this issue come from?
- This topic was modified 2 years, 3 months ago by .
- This topic was modified 2 years, 3 months ago by .
- This topic was modified 2 years, 3 months ago by .
- This topic was modified 2 years, 3 months ago by .
- This topic was modified 2 years, 3 months ago by .
- This topic was modified 2 years, 3 months ago by .
- This topic was modified 2 years, 3 months ago by .
The topic ‘why my HTML code in header does not work?’ is closed to new replies.
