• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

The Right Way to Use JavaScript in Your WordPress Plugin ...

how to properly use JavaScript in your WordPress plugins. There are two key parts: 1. Use wp_enqueue_script() to load external libraries and standalone scripts, instead of generating your own script header tags.

View More Info

How to properly use JavaScript in your WordPress plugins. There are two key parts:

   1. Use wp_enqueue_script() to load external libraries and standalone scripts, instead of generating your own script header tags.
   2. On admin pages, use the admin_print_scripts-[mypage] action hook to register the code on only your plugin’s page, not every admin page.

Both of those techniques have been available since WordPress 2.1, so plugin authors can be pretty confident that there will be no backwards-compatibility issues in employing them. (Despite the fact that WordPress is maintaining the 2.0.x version line until 2010, my research suggests that the number of users of that branch is insignificant.)

- Don’t pollute the global JavaScript namespace, especially with the over-used “$”. A number of JavaScript libraries use the dollar sign in different ways, so you can run into problems if, for example, you’re using jQuery but another plugin has loaded Prototype.

Fortunately, jQuery makes it easy to use “$” in a friendly way with other libraries. My favorite is to wrap jQuery-based code in something like the following, which employs $ outside of the global namespace and waits to execute the script until after the DOM has loaded.

jQuery(function($) { /* some code that uses $ */ });

source: pressedwords

 View Full Story.
Posted at 02:47:58 pm | Permalink | Posted in How to Blog  WordPress Plugins  

Related Stuff

New WordPress feature, Possibly Related Posts

If you have a blog on WordPress.com, you may have noticed a new feature called Possibly Related that links posts from other blogs in the ...

What Do You Need to Set up a Wordpress Blog

I've found myself answering this question a lot lately, so I figure I should just turn it into a blog post so I can point people to ...

How To Make a WordPress Privacy Policy

Ever since Adsense updated their terms and conditions, requiring publishers to display a privacy policy on their website(s), webmasters and ...

WordPress Single Post Templates

Austin recommends using a filter in your functions.php file as an alternative to the method below. IMO, his suggestion is much simpler and ...

Wordpress Plugin - SuperFast Digg This

SuperFast Digg This is really a super fast social bookmarking plugin, it loads faster than others, scalable and with better performance. It ...

Be the first ... |Add your comment.

Your Comment ...

  Name (required)

  Email (required, hidden)

  Website


About Webloglines

Webloglines is a project offers a comprehensive collection of blogging services, articles, themes and plugins from around the world. Whether you're looking to promote your own blog or find blogs on various topics, this site is for you.


Recent Stuff

New WordPress feature, Possibly Related Posts

What Do You Need to Set up a Wordpress Blog

How To Make a WordPress Privacy Policy

WordPress Single Post Templates

Wordpress Plugin - SuperFast Digg This

Fast-Static-Feed WordPress Plugin


Our Partners

Ajax Projects

Web 2.0 Sites

Webloglines

Human Development Handbook

Software Development Company

Ajaxlines


Search


Topics

  • Blogging Tips (40)
  • Blogs Slides (25)
  • Blogs Websites (22)
  • How to Blog (22)
  • Search Engines (1)
  • WordPress Plugins (14)
  • WordPress Security (4)
  • Wordpress Themes (11)
  • Wordpress Tips (9)

© 2006 www.webloglines.com. All Rights Reserved. Powered by IRange