isn't there any way to load a script through wp_enqueue_scripts and have my script instead of in a file, in a variable declared earlier? Something like:

add_action('wp_enqueue_scripts', 'ajax_check_payment');
function ajax_check_payment() {
    $script = <<<JS
    <script type="text/javascript">
    jQuery(function($) {
        $(document).ready(function() {

    wp_enqueue_script('ajax_check_course_payment', $script, array('jquery'), time());

1 Answer 1


Unfortunately, wp_enqueue_script doesn't work that way — the second parameter is for a URL as per the documentation.

But you could use wp_add_inline_script() (if there's an enqueue'd script to attach it to) or, as in olden times, just hook in to wp_head or wp_footer.

  • Yup, that's what I'm gonna do... I'll use wp_footer. Thanks! :)
    – Faye D.
    Sep 25, 2022 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.