Having this issue for months and I got it now running when I posted the question here. the issue is that the wp_enqueue_script needs to have the script file register first. So I have it working this way!
if (! function_exists('custom_jsfiles')) {
add_action('wp_enqueue_scripts', 'custom_jsfiles');
function custom_jsfiles() {
wp_register_script('custom_js', get_theme_file_uri().'/mytheme/custom-js.js');
wp_enqueue_script('custom_js');
}
}
########################
updating the answer,
the path wasnt correct, also has jacob said, no need to register them
And now its working
function ad_ficheiros(){
wp_enqueue_script('custom_js', get_template_directory_uri().'/inc/custom-js.js', array(), '1.15', true);
}
add_action('wp_enqueue_scripts', 'ad_ficheiros');
here the file is on a folder called inc inside the themes folder, also added two more parameters, the file version and if it is to be shown in the header or footer(false or true).