Add JavaScript to a Theme
If you want to add a JavaScript file to a theme, you can use the snippet below:
function wpkb_add_my_js() {
wp_enqueue_script( 'my-js', get_stylesheet_directory_uri() . '/js/script.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpkb_add_my_js' );
Related Posts
- Enable Asset Caching When Using Laravel
- Use Google Fonts Locally With GeneratePress
- Add Custom CSS Styles to WordPress Visual Editor
- Always Show the "Read More" Link When Using the Astra Theme
- GeneratePress - Add Wrap Around Content
- Avoid WPForms Spam by Implementing a Custom Honeypot
- Add Relevanssi 'did you mean' to Genesis Theme
- Update Rewrite Rules