• Hello! I have this line of PHP that I want to insert in a sidebar widget, but only if certain conditions are met:

    <script>
       if (window.innerWidth > 1024) { //Somehow call PHP here }
    </script>

    I created a shortcode for the PHP and tried putting it inside document.write(''); but that didn’t work.

    <script>
       if (window.innerWidth > 1024)
            { document.write('[shortcode]'); } //doesn't work
    </script>

    Please help. Thanks.

The topic ‘Call a PHP snippet inside JavaScript?’ is closed to new replies.