Skip to content

wp_add_inline_script() is broken after update to 1.0.4 #20

@LukePPx

Description

@LukePPx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions