• kokoruz

    (@kokoruz)


    I am developing a Content Security Policy and implementing the use of none for my inline scripts. When I add php to my javascript to echo out the nonce value from my function/variable it renders the php as text and does not display the nonce value. How can I use php inside of javascript in this plugin?

    <script nonce="<?php echo esc_attr($GLOBALS['csp_nonce']); ?>">

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kokoruz

    (@kokoruz)

    I just thought I would add, when I echo out the nonce value outside of the plugin it works. I presume there is a setting in the plugin preventing this and I am hoping I can adjust the setting.

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hey @kokoruz,

    If you want to use PHP in JavaScript please use the Universal Code Type and wrap the JavaScript code in script tags.

    That way, PHP will get executed and you can use the nonce as you intend.

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

The topic ‘PHP in Javascript’ is closed to new replies.