Title: PHP in Javascript
Last modified: March 27, 2025

---

# PHP in Javascript

 *  [kokoruz](https://wordpress.org/support/users/kokoruz/)
 * (@kokoruz)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/php-in-javascript/)
 * 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](https://wordpress.org/support/users/kokoruz/)
 * (@kokoruz)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/php-in-javascript/#post-18386303)
 * 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](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/php-in-javascript/#post-18386343)
 * Hey [@kokoruz](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

## Tags

 * [CSP](https://wordpress.org/support/topic-tag/csp/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [nonce](https://wordpress.org/support/topic-tag/nonce/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 2 replies
 * 2 participants
 * Last reply from: [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * Last activity: [1 year, 2 months ago](https://wordpress.org/support/topic/php-in-javascript/#post-18386343)
 * Status: not resolved