<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pressed Words &#187; JavaScript</title>
	<atom:link href="http://pressedwords.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://pressedwords.com</link>
	<description>News and commentary about all things WordPress</description>
	<lastBuildDate>Thu, 11 Jun 2009 03:54:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1</generator>
	<item>
		<title>The Right Way to Use JavaScript in Your WordPress Plugin</title>
		<link>http://pressedwords.com/wordpress-javascript-compatibility/</link>
		<comments>http://pressedwords.com/wordpress-javascript-compatibility/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 14:27:32 +0000</pubDate>
		<dc:creator><![CDATA[Austin Matzko]]></dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://pressedwords.com/?p=48</guid>
		<description><![CDATA[Ozh explains how to properly use JavaScript in your WordPress plugins. There are two key parts: Use wp_enqueue_script() to load external libraries and standalone scripts, instead of generating your own script header tags. On admin pages, use the admin_print_scripts-[mypage] action hook to register the code on only your plugin&#8217;s page, not every admin page. Both [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Ozh explains how to <a href="http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/">properly use JavaScript in your WordPress plugins</a>.  There are two key parts:</p>
<ol>
<li>Use <code>wp_enqueue_script()</code> to load external libraries and standalone scripts, instead of generating your own script header tags.</li>
<li>On admin pages, use the <code>admin_print_scripts-[mypage]</code> action hook to register the code on only your plugin&#8217;s page, not every admin page.</li>
</ol>
<p>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 <a href="http://wordpress.org/download/legacy/">maintaining the 2.0.x version line until 2010</a>, my research suggests that the <a href="http://pressedwords.com/how-many-bloggers-use-each-version-of-wordpress/">number of users of that branch is insignificant</a>.) </p>
<p>I would add one more tip to Ozh&#8217;s: don&#8217;t pollute the global JavaScript namespace, especially with the over-used &#8220;$&#8221;.  A number of JavaScript libraries use the dollar sign in different ways, so you can run into problems if, for example, you&#8217;re using jQuery but another plugin has loaded Prototype. </p>
<p>Fortunately, jQuery makes it easy to <a href="http://docs.jquery.com/Using_jQuery_with_Other_Libraries">use &#8220;$&#8221; in a friendly way with other libraries</a>. My favorite is to wrap jQuery-based code in something like the following, which employs <code>$</code> outside of the global namespace <em>and</em> waits to execute the script until after the DOM has loaded. </p>
<p><code>jQuery(function($) { /* some code that uses $ */ });</code></p>
]]></content:encoded>
			<wfw:commentRss>http://pressedwords.com/wordpress-javascript-compatibility/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/5 queries in 0.001 seconds using memcached
Object Caching 231/234 objects using memcached

 Served from: pressedwords.com @ 2026-04-03 17:58:28 by W3 Total Cache -->