Custom theme JavaScript not working
-
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?
- The topic ‘Custom theme JavaScript not working’ is closed to new replies.