I am attempting to design my own wordpress theme, but I'm having issues getting my JavaScript to work, and nothing I have researched seems to have the answer. If anyone can help me out I'd greatly appreciate it!
Things I have done:
Enqueue my javascript file in functions.php:
function sorenTheme_scripts() {
wp_enqueue_style('style', get_stylesheet_uri());
wp_register_script( 'soren-script', get_template_directory_uri() . '/js/soren-script.js', array( 'jquery', 'jquery-ui-core' ), '1', true );
wp_enqueue_script('soren-script');
}
add_action('wp_enqueue_scripts', 'sorenTheme_scripts');
Create a simple javaScript file in the directory {template folder}/js named soren-script.js, which currently just contains a very simple alert test
alert('Hello World');
and that's it. When I tried to put the alert in the index.php file directly using the script tags, the alert came up as expected, but when I move it to the js file I get nothing. Is there something i need to add to the .php or .js files?
EDIT: When I look at the developer console, the source files include jquery, my css file, etc but not soren-script.js
So I guess getting soren-script.js to show up would fix the problem but I don't know how to do that, i thought the enqueue would make it automatically show up as a source, as it did with my style sheet