Print this page
Thursday, 26 December 2013 15:45

how to add scripts and styles in wordpress admin page

Written by 
Rate this item
(0 votes)
In wordpress there are some error free ways to add scripts and styles
in your custom  page in admin dashboard.If you don't follow these rules you
might see errors and it's not a good idea to declare script and styles without
this kind of some pre-defined actions.
So in main plugin page add -

add_action('admin_print_styles', 'mitsol_admin_css_all_page');

this action - "admin_print_styles" is responsible for injecting script and style
files in head section in your admin page.So now you will add above registered function
as follows -

function mitsol_admin_css_all_page() {    

  wp_register_script('mitsol_feed_bootstrap_js', plugins_url('js/my_js_file.js', __FILE__), array("jquery"));
  wp_register_style($handle = 'mitsol_feed', $src = plugins_url('css/custom_css.css', __FILE__), $deps = array(), $ver = '1.0.0', $media = 'all');

"wp_enqueue_script" gonna register jquery at first  
"wp_register_script" will register custom javascript file for your admin page, for
this, in addition, you have to include "wp_enqueue_script" also as above function shows.

In the same way follow the last two lines above for injecting style files.
Read 2436 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments