Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to load a css and js file for use in WP admin only... WordPress


I just want to know the best way to load/include a css and js file in the wp admin when a certain theme is activated. These files will be exist inside the theme folder.


I'd like to call them both from my functions.php file.

Answers (1)


Buzu B answers:

You need to use a conditional and check if you are in admin area:

wp_enqueue_script();//params needed.
wp_enqueue_style();//params needed

Check the documentation for more info:

[[LINK href=""]][[/LINK]]
[[LINK href=""]][[/LINK]]
[[LINK href=""]][[/LINK]]

Joe Calithia comments:

I was hoping for an exact solution using my file paths included in the question. Still a little confused after looking over the wp docs.

Buzu B comments:

I can do it for you and then explain how I did it.
I will send you a direct message with my contact information.

Buzu B comments:

Try this:
$src1 = get_bloginfo('stylesheet_url') . '/library/css/admin.css';
$src2 = get_bloginfo('stylesheet_url') . '/library/scripts/admin.js';
wp_enqueue_script( 'myThemeScript', $src2, '', '', true );
wp_enqueue_style( 'myThemeStyle', $src1, '', '', 'screen' );

It should work just fine. In case it doesn't, look at the source code generated by the browser and check the paths being generated.
That code should go on your functions.php file.

Joe Calithia comments:

Thanks Buzu.

Actually the stylesheet_url needed to be template_url which seems to be working.