I am in the process of converting a mobile responsive page, currently built in Bootstrap into WordPress.
Using wp_register_style()
and wp_enqueue_style()
will add the stylesheets to all pages, including the wp-admin. I know I could get around that by using an if ( ! is_admin() )
conditional statement.
Is it better to use the conditional statement, or to just to use:
<link rel="stylesheet" type="text/css" href="https://wordpress.stackexchange.com/questions/112352/<?php bloginfo("template_directory'); ?>/bootstrap.css" media="screen" />
in the theme’s header.php?
3 Answers
To load scrpits only in front-end pages use:
add_action( 'wp_enqueue_scripts', 'my_front_end_scripts' );
function my_front_end_scripts(){
wp_enqueue_script('script_handle');
wp_enqueue_style('style_handle');
}
To load scripts only in login use:
add_action( 'login_enqueue_scripts', 'my_login_scripts');
function my_login_scripts(){
wp_enqueue_script('script_handle');
wp_enqueue_style('style_handle');
}
To load scripts only in admin use:
add_action('admin_enqueue_scripts','my_admin_scripts');
function my_admin_scripts(){
wp_enqueue_script('script_handle');
wp_enqueue_style('style_handle');
}