How to add both styles and scripts within the function

Previously we have discussed about adding styles and scripts through Hooks separately. If you haven’t gone through please visit the How to add styles through Hooks in WordPress. and How to add Scripts through Hooks in WordPress

To use both within the function you just need to use both styles and scripts within the same function

function nero_resources() {
wp_register_style( ‘nero_bootstrap’, get_template_directory_uri() . ‘path/to/bootstrap.css’ );
wp_enqueue_style( ‘nero_bootstrap’ );

wp_register_script( ‘nero_bootstrap’, get_template_directory_uri() . ‘/path/to/bootstrap.js’ );
wp_enqueue_script( ‘jquery’ );
wp_enqueue_script( ‘nero_bootstrap’ );
}
add_action( ‘wp_enqueue_scripts’, ‘nero_resources’ );
function nero_resources() {
wp_register_style( ‘nero_bootstrap’, get_template_directory_uri() . ‘path/to/bootstrap.css’ );
wp_enqueue_style( ‘nero_bootstrap’ );

wp_register_script( ‘nero_bootstrap’, get_template_directory_uri() . ‘/path/to/bootstrap.js’ );
wp_enqueue_script( ‘jquery’ );
wp_enqueue_script( ‘nero_bootstrap’ );
}
add_action( ‘wp_enqueue_scripts’, ‘nero_resources’ );

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *