WordPress add inline JavaScript

This is the WordPress way to add inline JavaScript if you have no script dependencies:

wp_register_script( 'dummy-handle', '' );
wp_enqueue_script( 'dummy-handle' );
wp_add_inline_script( 'dummy-handle', 'var my_variable = true;', 'before' );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.