WordPress/jQuery Best Practices
I’ve spent a lot of time recently fixing bugs that other developers have left floating around. Here’s a quick how-to on preventing those bugs. 1. Use wp_enqueue_script() in your WordPress themes When you write a WordPress theme, you’re bound to use a number of snippets of JavaScript to accomplish different things. But just how should you embed that JavaScript? I thought (incorrectly) for a long time that you could simply include the <script> tag between the <head></head> tags and reference the script: <head> <script type=”text/javascript” src=”<? bloginfo(‘template_url’) ?>/js/myscript.js”></script> </head> Well, let me tell you, folks, that doing it that way just won’t cut the muster. Why? Well, what happens if you do this: <head> <script type=”text/javascript” src=”<? bloginfo(‘template_url’) ?>/js/my.jquery.js”></script> <script… [Read More]