I am trying to link a javascript file to my child topic. I have seen the WordPress codecs and many examples, but it still does not work. I am working on the local host, so I want to use get_stylesheet_directory () which I have read. I have echoed it and it is pointing to the right path. Below is my code which is placed in my child functions.php theme:
add_action ('wp_enqueue_scripts', 'theme_js'); Function theme_js () {wp_enqueue_script ('theme_js', get_stylesheet_directory (). '/js/theme.js', array ('jquery'), '', is true); }
My JavaScript file looks like this:
/ ** * Custom Theme Styles * / (Function ($) {$ ('Main - Navigation Lea '(function () {var link = $ (this) .attr (' href '); $ (' html, body '). Animate ({scrollTop: $ (link) .offset ( ) Top}, 1500);});}) (jQuery);
The source string should be a URL, not a path, so you should get the get_stylesheet_directory_uri ()
instead of get_stylesheet_directory ()
:
add_action ( 'Wp_enqueue_scripts', 'theme_js') Is required; function theme_js () {wp_enqueue_script ('theme_js', get_stylesheet_directory_uri (). '/js/theme.js', array ('jquery'), '', true);}
No comments:
Post a Comment