0

I have a plugin, from which within one of the files I am trying to include a JS file the proper way:

function inveroak_feed_search_enqueue() {
    wp_enqueue_script('inveroak-feed-search', plugin_dir_url(__file__).'assets/js/search.js');
}
add_action('wp_enqueue_scripts', 'inveroak_feed_search_enqueue');

Further down the file I am referencing this function from an input field like this:

<input onkeyup="inveroak_feed_search(this)" />

However, whenever I press any key within the input, all I see is this in the console (and the JS file isn't being loaded also).

Uncaught ReferenceError: inveroak_feed_search is not defined at HTMLInputElement.onkeyup ((index):120)

Contents of search.js if it helps:

function inveroak_feed_search(element) {
    (function($) {
        var value = $(element).val();
        $(".inveroak-feed-container").each(function() {
            if ($(this).find(".op-name,.op-pin,.op-toolbox li").text().toLowerCase().search(value.toLowerCase()) > -1) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
    })(jQuery);
}

Can anyone help why this JS file isn't loading?

1
  • 1
    Have you checked if there’s a script tag on the page? And if the URL is correct? Nov 30 '21 at 12:39
0

You can also load like this way:

echo "<script src='".plugins_url('your_plugin_folder_name/assets/js/search.js')."'></script>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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