Sunday, May 15, 2011

External Javascript in Wordpress

JS for admin pages:
Wordpress provides some very important action hooks to hook external js in admin pages.
admin_enqueue_scripts : it prints external js in every pages in your admin sides,very much awful,isn't it? Better method is also available.cheers!

Suppose you create a setting page for your plugins and it uses js files.You have to follow some rules to be using this js file only for this script.
(i) $a = add_menu_page(.....) || add_submenu_page() || any page
(ii)ehco $a(let $a = settings_page_WPAffiliateLinks);
(iii)extend it with this hooks like this
admin_print_scripts-settings_page_WPAffiliateLinks
very simple isn't it?

js for client sides
You can use some build in functin like is_home(),is_single() to print your js scripts for client sides.




No comments:

Post a Comment