-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Version
1.0.4
What did you expect to happen?
wp_add_inline_script() is working as expected. All three script tags are added after each other.
What actually happens?
The script tags are nested within each other.
<script>
console.log("Before moment");
//# sourceURL=moment-js-before
<script src="https://example.com/wp/wp-includes/js/dist/vendor/moment.js?ver=2.30.1"></script>
<script>
moment.updateLocale( 'de_DE', {"months":["Januar","Februar","M\u00e4rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],"monthsShort":["Jan.","Feb.","M\u00e4rz","Apr.","Mai","Juni","Juli","Aug.","Sep.","Okt.","Nov.","Dez."],"weekdays":["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],"weekdaysShort":["So.","Mo.","Di.","Mi.","Do.","Fr.","Sa."],"week":{"dow":1},"longDateFormat":{"LT":"G:i","LTS":null,"L":null,"LL":"j. F Y","LLL":"j. F Y, G:i","LLLL":null}} );
console.log(moment().format());
//# sourceURL=moment-js-after
</script></script>Steps to reproduce
Add this to your functions.php in your theme folder:
function test_scripts() {
wp_enqueue_script( 'moment', 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment.min.js' );
wp_add_inline_script( 'moment', 'console.log("Before moment");', 'before' );
wp_add_inline_script( 'moment', 'console.log(moment().format());', 'after' );
}
add_action( 'wp_enqueue_scripts', 'test_scripts' );System info
Radicle 2.2.0
Wordpress 6.9
Log output
Uncaught SyntaxError: Unexpected token '<' (at moment-js-before:202:1)
moment-js-after:2 Uncaught ReferenceError: moment is not defined
at moment-js-after:2:1
Please confirm this isn't a support request.
Yes
danlapteacru, codepuncher, ehclau, krisvanderven, davideprevosto and 5 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working