htmlwordpresselementorsurveymonkey

Wordpress Elementor script inside html "Server Error"


To embed my surveymonkey on my website I received the script code and copied it inside an html section. I placed this html section with Elementor at the center of the page.

<script>(function(t,e,s,n){var o,a,c;t.SMCX=t.SMCX||[],e.getElementById(n)||(o=e.getElementsByTagName(s),a=o[o.length-1],c=e.createElement(s),c.type="text/javascript",c.async=!0,c.id=n,c.src="https://widget.surveymonkey.com/collect/website/js/<TokenToMySurvey>.js",a.parentNode.insertBefore(c,a))})(window,document,"script","smcx-sdk");</script>

Now I face to issues. First, the survey is displayed in the preview but at the bottom of the page. Second, as I hit "Save" or "Publish" I get

Server Error (510 No Reason Phrase)

How do I put the script part correctly inside the html?


Solution

  • You can try to create a shortcode by adding the code below to your theme's functions.php (Preferably into your child theme's functions.php)

    I made up the shortcode name fiscblogsurvey and function name. You can call them whatever you want.

    // function that runs when shortcode is called
    function fiscblog_shortcode() { 
        return '<script>(function(t,e,s,n){var o,a,c;t.SMCX=t.SMCX||[],e.getElementById(n)||(o=e.getElementsByTagName(s),a=o[o.length-1],c=e.createElement(s),c.type="text/javascript",c.async=!0,c.id=n,c.src="https://widget.surveymonkey.com/collect/website/js/<TokenToMySurvey>.js",a.parentNode.insertBefore(c,a))})(window,document,"script","smcx-sdk");</script>';
    } 
    // register shortcode
    add_shortcode('fiscblogsurvey', 'fiscblog_shortcode'); 
    

    You can now add this shortcode into elementor using elementor's shortcode widget by typing inside [fiscblogsurvey]