• I pasted a few lines of code into the head section of my website. When I’m logged in as the site administrator, I can see the code and it works properly. When I’m not logged in – or someone from the public – access the site, the script is hidden and does. not execute. I just see the beginning comments: <!– Begin Mainn script –>
    <!–End Mainn script –>

    The script in between is missing.

    There are plenty of other scripts – google tags, meta pixel, etc – that are working properly.

    Any suggestions on getting the code to display and execute?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator threadi

    (@threadi)

    How exactly did you insert this code?

    Thread Starter petermainnwp

    (@petermainnwp)

    We added the code three different ways. and all of them resulted in the same situation.

    • we used the WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager plugin
    • We went straight to the files and added it
    • We created a custom plugin

    For all three, the code is invisible when deployed – except for the beginning and ending comments.

    We see the code and it works properly when logged in.

    @whyviru , there is no mention of a “user” restriction condition in the head. The code we’ve inserted is:

    <!-- Begin Mainn script -->
    <script
    async
    data-mainn-id="123"
    data-environment="production"
    id="mainn-widget-script"
    src="https://widget.mainn.io/scripts/mainn-widget.js"
    ></script>
    <!-- End Mainn script -->

    the “123” is just an example. this code won’t work without a registered mainnID

    • This reply was modified 1 year, 4 months ago by petermainnwp.
    Moderator threadi

    (@threadi)

    WordPress removes JavaScripts inserted “just like that” for security reasons. It is therefore not possible to insert this code just like that.

    This article describes the options in more detail: https://www.wpbeginner.com/wp-tutorials/how-to-easily-add-javascript-in-wordpress-pages-or-posts/ – be sure to use the options described here. With WPCode, for example, you must insert it as a JavaScript snippet.

    Thread Starter petermainnwp

    (@petermainnwp)

    Thank you, @threadi ,

    We are using the WPCode – Insert Headers and Footers plugin as suggested in the article. I’m also using this code on other sites with no errors. I’m wondering if the issue is a conflict with other plugins.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Script code is not showing – only when logged in’ is closed to new replies.