custom js css using wordpress hook
Sure! Here is an example of how you can add custom JavaScript and CSS using WordPress hooks:
- Locate the functions.php file in your WordPress theme directory.
- To add custom JavaScript, use the wp_enqueue_script function within the functions.php file. Here's an example:
function custom_scripts() {
wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), '1.0', true );
}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );
- To add custom CSS, use the wp_enqueue_style function within the functions.php file. Here's an example:
function custom_styles() {
wp_enqueue_style( 'custom-css', get_template_directory_uri() . '/css/custom.css', array(), '1.0', 'all' );
}
add_action( 'wp_enqueue_scripts', 'custom_styles' );
These steps will add your custom JavaScript and CSS files to your WordPress theme using the appropriate hooks.