Created
March 6, 2023 06:45
-
-
Save nkb-bd/bdc217a143b7c4dd870bcda33c09ff81 to your computer and use it in GitHub Desktop.
Random WordPress Filter & Hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//adding nonce in extra js inline script | |
add_filter('script_loader_tag', function ($tag, $handle) { | |
if ('script-handler' === $handle) { | |
$nonce = wp_create_nonce(); | |
$tag = str_replace('<script ', "<script nonce='$nonce' ", $tag); | |
} | |
return $tag; | |
}, 10, 2); | |
wp_add_inline_script( 'script-handler', ' const Vars = '.json_encode($vars) , 'before' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment