how to add a custom javascript file to our theme

Question

I add custom css files to my theme, but when I try to do the same for the javascript files, they dont seem to work, this means that the javascript on the html files is working properlly, but if I transfer it to the custom javascript file it doesnt.
Am I adding the custom javascript file correctly to wordpress?

if (! function_exists('custom_jsfiles')) {
    add_action('wp_enqueue_scripts', 'custom_jsfiles');
    function custom_jsfiles() {wp_enqueue_script('custom_js', home_url().'/wp-content/themes/mytheme/custom-js.js');}
}

0
fuxia 8 months 2021-12-21T11:40:58-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse