• Resolved Premiers

    (@sdnazdi)


    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/2d4p8JV

    however when I inserted this shortcode into a text inside posts or pages, it works fine.

    https://ibb.co/MskB4VK
    https://ibb.co/whRVtNW

    Please let me know where does this issue come from?

    • This topic was modified 2 years, 3 months ago by Premiers.
    • This topic was modified 2 years, 3 months ago by Premiers.
    • This topic was modified 2 years, 3 months ago by Premiers.
    • This topic was modified 2 years, 3 months ago by Premiers.
    • This topic was modified 2 years, 3 months ago by Premiers.
    • This topic was modified 2 years, 3 months ago by Premiers.
    • This topic was modified 2 years, 3 months ago by Premiers.
Viewing 1 replies (of 1 total)
  • Hello @sdnazdi

    I’m really sorry, but our policy does not offer support for custom code, be it implementing or debugging it. We recommend contacting a knowledgeable developer if you require assistance with implementing advanced solutions on your website.

    Thank you.

Viewing 1 replies (of 1 total)

The topic ‘why my HTML code in header does not work?’ is closed to new replies.