Skip to content

Commit 2d76eee

Browse files
authored
Merge pull request #12 from soderlind/fix/csp
Inline the custom JavaScript using wp_print_inline_script_tag()
2 parents 206e6da + 7d40c7e commit 2d76eee

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.1.6] - 2025-08-11
6+
7+
### Fixed
8+
- Inline the custom javascript using ` ()`
9+
- Ensure the script is printed in the footer
10+
511
## [1.1.5] - 2025-07-16
612

713
### Fixed

additional-javascript.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Plugin URI: https://github.com/soderlind/additional-javascript
1313
* GitHub Plugin URI: https://github.com/soderlind/additional-javascript
1414
* Description: Add additional JavaScript using the WordPress Customizer.
15-
* Version: 1.1.5
15+
* Version: 1.1.6
1616
* Author: Per Soderlind
1717
* Author URI: https://soderlind.no
1818
* Text Domain: additional-javascript
@@ -44,7 +44,7 @@
4444
);
4545

4646
add_action( 'init', __NAMESPACE__ . '\register_post_type_javascript', 0 );
47-
add_action( 'wp_head', __NAMESPACE__ . '\soderlind_custom_javascript_cb', 110 );
47+
add_action( 'wp_footer', __NAMESPACE__ . '\soderlind_custom_javascript_cb', 110 );
4848
add_action( 'customize_register', __NAMESPACE__ . '\register_additional_javascript' );
4949
add_action( 'customize_preview_init', __NAMESPACE__ . '\customize_preview_additional_javascript' );
5050
add_action( 'customize_controls_enqueue_scripts', __NAMESPACE__ . '\on_customize_controls_enqueue_scripts' );
@@ -120,11 +120,7 @@ function register_post_type_javascript() {
120120
function soderlind_custom_javascript_cb() {
121121
$javascript = soderlind_get_custom_javascript();
122122
if ( $javascript || is_customize_preview() ) {
123-
?>
124-
<script id="soderlind-custom-javascript">
125-
<?php echo $javascript; ?>
126-
</script>
127-
<?php
123+
wp_print_inline_script_tag( $javascript, [ 'id' => 'soderlind-custom-javascript' ] );
128124
}
129125
}
130126

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "additional-javascript",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"description": "Add additional JavaScript using the WordPress Customizer.",
55
"keywords": [
66
"wordpress",

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: javascript, customizer, code, custom code, js
44
Donate link: https://paypal.me/PerSoderlind
55
Requires at least: 6.5
66
Tested up to: 6.8
7-
Stable tag: 1.1.5
7+
Stable tag: 1.1.6
88
Requires PHP: 8.2
99
License: GPL-2.0+
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@@ -62,6 +62,10 @@ The JavaScript is added at the end of the `<head>` section of your site with a p
6262

6363
== Changelog ==
6464

65+
= 1.1.6 =
66+
* Inline the custom javascript using `wp_print_inline_script_tag()`
67+
* Ensure the script is printed in the footer
68+
6569
= 1.1.5 =
6670
* Fixed deprecated PHP string interpolation syntax for PHP 8.2+ compatibility
6771

0 commit comments

Comments
 (0)