For a moment, I wondered if my test site got hacked — my WordPress site’s dashboard was all broken (cosmetically). But when i looked at the source code of the page, I noticed that the “scripts and styles” that I enqueued for the front-end were also enqueued in the backend as well.
This is how I did it:
add_action('init','wpse54189_register_script');
function wpse54189_register_script(){
wp_register_script( 'aahan_bootstrap_transition', get_template_directory_uri().'/js/bootstrap-transition.js');
wp_register_script( 'aahan_bootstrap_carousel', get_template_directory_uri().'/js/bootstrap-carousel.js');
wp_register_script( 'aahan_bootstrap_carousel_cycler', get_template_directory_uri().'/js/bootstrap-carousel-cycler.js', array('jquery', 'aahan_bootstrap_transition', 'aahan_bootstrap_carousel'));
wp_enqueue_script( 'aahan_bootstrap_carousel_cycler' );
wp_enqueue_script( 'comment-reply' );
wp_register_script( 'aahan_ajax_comment', get_template_directory_uri().'/js/no-reload-comments.js', array('jquery'));
wp_localize_script( 'aahan_ajax_comment', 'yjlSettings', array(
'gifUrl'=> get_template_directory_uri().'/images/ajax-loader.gif',
'autoGrow'=> 'enable'
));
wp_enqueue_script( 'aahan_ajax_comment' );
}
add_action('init','aahan_register_style');
function aahan_register_style(){
wp_register_style( 'aahan_webfonts_stylesheet', get_template_directory_uri().'/font/font.css');
wp_register_style( 'aahan_main_stylesheet', get_template_directory_uri().'/style.css', array('aahan_webfonts_stylesheet'));
wp_enqueue_style( 'aahan_main_stylesheet' );
}
What could be wrong here?
The “init” action runs both on frontend page loads, and on backend page loads.
Try hooking these to the “wp_enqueue_scripts” action instead. I believe it does not run on admin page loads.
Example Code: (By OP)
Just add the condition
So you will have