Title: Making Inline Script Inject via
Last modified: July 10, 2025

---

# Making Inline Script Inject via

 *  [darbrett](https://wordpress.org/support/users/darbrett/)
 * (@darbrett)
 * [10 months ago](https://wordpress.org/support/topic/making-inline-script-inject-via/)
 * I’m working on setting up CSP headers for a site, and while adding a nonce to
   the scripts I encountered problems with one of the scripts in WP Fastest Cache
   because it’s just printed into the page inline, and it’s dynamically generated
   so I can’t just use a hash for it. It’s tiny change to make it. This lets other
   code attach attributes such as the nonce to the script tag as outlined here: 
   [https://make.wordpress.org/core/2021/02/23/introducing-script-attributes-related-functions-in-wordpress-5-7/](https://make.wordpress.org/core/2021/02/23/introducing-script-attributes-related-functions-in-wordpress-5-7/)
   
   I’ve tested it locally offline and it appears to be working – would you be able
   to incorporate this into the plugin?
 *     ```wp-block-code
       Index: inc/admin-toolbar.php===================================================================--- inc/admin-toolbar.php	(revision 3325388)+++ inc/admin-toolbar.php	(working copy)@@ -31,12 +31,8 @@ 		}  		public function print_my_inline_script() {-			?>-			<script type="text/javascript">-				var wpfc_ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";-				var wpfc_nonce = "<?php echo wp_create_nonce("wpfc"); ?>";-			</script>-			<?php+			$inline_script = 'var wpfc_ajaxurl = "' . admin_url('admin-ajax.php') . '"; var wpfc_nonce = "' . wp_create_nonce('wpfc') . '";';+			wp_add_inline_script('wpfc-toolbar', $inline_script, 'before'); 		}  		public function wpfc_tweaked_toolbar_on_frontpage() {
       ```
   

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

 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [10 months ago](https://wordpress.org/support/topic/making-inline-script-inject-via/#post-18550144)
 * does the following code solve your problem?
 *     ```wp-block-code
       public function print_my_inline_script() {			$script = "				var wpfc_ajaxurl = '" . admin_url('admin-ajax.php') . "';				var wpfc_nonce = '" . wp_create_nonce("wpfc") . "';			";			echo wp_print_inline_script_tag($script);		}
       ```
   
 *  Thread Starter [darbrett](https://wordpress.org/support/users/darbrett/)
 * (@darbrett)
 * [10 months ago](https://wordpress.org/support/topic/making-inline-script-inject-via/#post-18550219)
 * Hi Emre, thanks for your quick response.
 * Yes, that looks like works just as well. The script element is generated with
   the nonce attribute I’m trying to add.
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [10 months ago](https://wordpress.org/support/topic/making-inline-script-inject-via/#post-18551112)
 * thank you so much.
 * I updated the code. It will be available in the next version.

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

The topic ‘Making Inline Script Inject via’ is closed to new replies.

 * ![](https://ps.w.org/wp-fastest-cache/assets/icon-256x256.png?rev=2064586)
 * [WP Fastest Cache - WordPress Cache Plugin](https://wordpress.org/plugins/wp-fastest-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-fastest-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-fastest-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-fastest-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-fastest-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-fastest-cache/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * Last activity: [10 months ago](https://wordpress.org/support/topic/making-inline-script-inject-via/#post-18551112)
 * Status: not resolved