<?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>Ian Dunn &#187; WordPress</title>
	<atom:link href="http://iandunn.name/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://iandunn.name</link>
	<description>Seattle-based web developer blogging about tips and solutions</description>
	<lastBuildDate>Sat, 04 Feb 2012 00:22:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>WordPress Backup Options</title>
		<link>http://iandunn.name/wordpress-backup-options/</link>
		<comments>http://iandunn.name/wordpress-backup-options/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 00:22:06 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Backups]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=1162</guid>
		<description><![CDATA[Nathan Ingram put together a thorough post on <a title="Backup Strategies for your Web Site" href="http://nathaningram.com/recommendations/worryproof-wordpress-backup-strategies-for-your-web-site/">backing up WordPress</a> and a <a title="WordPress backup options comparison chart" href="http://nathaningram.com/wp-content/uploads/2012/01/Backup-Options-Comparison.pdf">chart comparing various plugins and services</a> .]]></description>
			<content:encoded><![CDATA[<p>Nathan Ingram put together a thorough post on <a title="Backup Strategies for your Web Site" href="http://nathaningram.com/recommendations/worryproof-wordpress-backup-strategies-for-your-web-site/">backing up WordPress</a> and a <a title="WordPress backup options comparison chart" href="http://nathaningram.com/wp-content/uploads/2012/01/Backup-Options-Comparison.pdf">chart comparing various plugins and services</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/wordpress-backup-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Placing Snippets in a Functionality Plugin Instead of Theme</title>
		<link>http://iandunn.name/placing-snippets-in-a-functionality-plugin-instead-of-theme/</link>
		<comments>http://iandunn.name/placing-snippets-in-a-functionality-plugin-instead-of-theme/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 19:17:18 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Functionality Plugin]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=1107</guid>
		<description><![CDATA[Dave Clements has a great suggestion for adding snippets to a WordPress site in a way that will preserve them between theme changes: create a simple <a title="Create a Functionality Plugin Instead of Using Functions.php" href="http://www.doitwithwp.com/create-functions-plugin/">functionality plugin</a> .]]></description>
			<content:encoded><![CDATA[<p>Dave Clements has a great suggestion for adding snippets to a WordPress site in a way that will preserve them between theme changes: create a simple <a title="Create a Functionality Plugin Instead of Using Functions.php" href="http://www.doitwithwp.com/create-functions-plugin/">functionality plugin</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/placing-snippets-in-a-functionality-plugin-instead-of-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scaling WordPress Installations</title>
		<link>http://iandunn.name/scaling-wordpress-installations/</link>
		<comments>http://iandunn.name/scaling-wordpress-installations/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 00:36:52 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Benchmarking]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Scaling]]></category>
		<category><![CDATA[TJ Stein]]></category>
		<category><![CDATA[Varnish]]></category>
		<category><![CDATA[WordCamp Chicago]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=1115</guid>
		<description><![CDATA[TJ Stein gave a really good <a title="Developing Fast &#38; Scalable Severs for WordPress" href="http://wordpress.tv/2012/01/05/tj-stein-developing-fast-scalable-severs-for-wordpress/">presentation</a> at WordCamp Chicago 2011 about scaling and performance issues with WordPress installations. He focuses a lot on using ngnix instead of Apache, but also covers PHP object caching, Varnish, CDNs, benchmarking, etc. It&#8217;s a good overview of current practices, but there&#8217;s also a lot of specific tips throughout.]]></description>
			<content:encoded><![CDATA[<p>TJ Stein gave a really good <a title="Developing Fast &amp; Scalable Severs for WordPress" href="http://wordpress.tv/2012/01/05/tj-stein-developing-fast-scalable-severs-for-wordpress/">presentation</a> at WordCamp Chicago 2011 about scaling and performance issues with WordPress installations. He focuses a lot on using ngnix instead of Apache, but also covers PHP object caching, Varnish, CDNs, benchmarking, etc. It&#8217;s a good overview of current practices, but there&#8217;s also a lot of specific tips throughout.</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/scaling-wordpress-installations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Different Approaches to Building a Theme-based Site</title>
		<link>http://iandunn.name/different-approaches-to-building-a-theme-based-site/</link>
		<comments>http://iandunn.name/different-approaches-to-building-a-theme-based-site/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 17:42:33 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Child Themes]]></category>
		<category><![CDATA[Custom Themes]]></category>
		<category><![CDATA[Premium Themes]]></category>
		<category><![CDATA[Theme Development]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=1066</guid>
		<description><![CDATA[Mark Root-Wiley wrote a great article on <a title="Choosing the Right WordPress Design Strategy for your Website" href="http://mrwweb.com/choosing-wordpress-theme-strategy-nonprofit-website/">the pros and cons of using premium themes, writing child themes and writing themes from scratch</a> . It&#8217;s discussed in the context of WordPress themes, but most of it is applicable to other CMSs as well. I think it&#8217;s a good introduction to give clients when discussing which method is best for their project.]]></description>
			<content:encoded><![CDATA[<p>Mark Root-Wiley wrote a great article on <a title="Choosing the Right WordPress Design Strategy for your Website" href="http://mrwweb.com/choosing-wordpress-theme-strategy-nonprofit-website/">the pros and cons of using premium themes, writing child themes and writing themes from scratch</a>. It&#8217;s discussed in the context of WordPress themes, but most of it is applicable to other CMSs as well. I think it&#8217;s a good introduction to give clients when discussing which method is best for their project.</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/different-approaches-to-building-a-theme-based-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Differences between query_posts(), get_posts() and WP_Query</title>
		<link>http://iandunn.name/differences-between-query_posts-get_posts-and-wp_query/</link>
		<comments>http://iandunn.name/differences-between-query_posts-get_posts-and-wp_query/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 18:22:01 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[get_posts()]]></category>
		<category><![CDATA[query_posts()]]></category>
		<category><![CDATA[WP_Query]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=1061</guid>
		<description><![CDATA[<a title="When should you use WP_Query vs query_posts() vs get_posts()?" href="http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts">This WordPress Answers page</a> explains the differences between the query_post() and get_posts() functions, and their relation to the WP_Query class. They both use WP_Query internally, but should be used in different contexts. Using them in the wrong context could lead to bugs that are hard to track down.]]></description>
			<content:encoded><![CDATA[<p><a title="When should you use WP_Query vs query_posts() vs get_posts()?" href="http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts">This WordPress Answers page</a> explains the differences between the query_post() and get_posts() functions, and their relation to the WP_Query class. They both use WP_Query internally, but should be used in different contexts. Using them in the wrong context could lead to bugs that are hard to track down.</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/differences-between-query_posts-get_posts-and-wp_query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Re-Abolish Slavery Ribbon</title>
		<link>http://iandunn.name/re-abolish-slavery-ribbon/</link>
		<comments>http://iandunn.name/re-abolish-slavery-ribbon/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 03:56:49 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Ethics and Values]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Human Trafficking]]></category>
		<category><![CDATA[Not For Sale]]></category>
		<category><![CDATA[Plugin Development]]></category>
		<category><![CDATA[Slavery]]></category>
		<category><![CDATA[Website Ribbon]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=1038</guid>
		<description><![CDATA[I just released <a title="Re-Abolish Slavery Ribbon" href="http://wordpress.org/extend/plugins/re-abolish-slavery-ribbon/">a new WordPress plugin</a> into the repository that raises awareness about <a href="http://www.polarisproject.org/human-trafficking/overview">modern-day slavery</a> by adding a &#8220;Re-Abolish Slavery&#8221; ribbon to WordPress sites. It&#8217;s running on this site, so  you can see a live example by looking in the upper-right hand corner. The ribbon links to the <a href="http://www.notforsalecampaign.org/">Not For Sale campaign</a> , which is one of the leading organizations involved in fighting human... [<a href="http://iandunn.name/re-abolish-slavery-ribbon/">more</a>]]]></description>
			<content:encoded><![CDATA[<p>I just released <a title="Re-Abolish Slavery Ribbon" href="http://wordpress.org/extend/plugins/re-abolish-slavery-ribbon/">a new WordPress plugin</a> into the repository that raises awareness about <a href="http://www.polarisproject.org/human-trafficking/overview">modern-day slavery</a> by adding a &#8220;Re-Abolish Slavery&#8221; ribbon to WordPress sites. It&#8217;s running on this site, so  you can see a live example by looking in the upper-right hand corner. The ribbon links to the <a href="http://www.notforsalecampaign.org/">Not For Sale campaign</a>, which is one of the leading organizations involved in fighting human trafficking.</p>
<p>You can <a href="http://wordpress.org/extend/plugins/re-abolish-slavery-ribbon/">download it at WordPress.org</a> if you&#8217;d like to install it on your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/re-abolish-slavery-ribbon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing WordPress Plugins</title>
		<link>http://iandunn.name/unit-testing-wordpress-plugins/</link>
		<comments>http://iandunn.name/unit-testing-wordpress-plugins/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 01:38:08 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Standards and Best Practices]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Integration Testing]]></category>
		<category><![CDATA[MockPress]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[Plugin Development]]></category>
		<category><![CDATA[Reflection]]></category>
		<category><![CDATA[SimpleTest]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=988</guid>
		<description><![CDATA[Nikolay Bachiyski gave a good talk at this year&#8217;s WordCamp San Francisco about <a title="Unit Testing Will Change Your Life" href="http://wordpress.tv/2011/08/20/nikolay-bachiyski-unit-testing-will-change-your-life/">unit testing WordPress plugins</a> . His method uses <a href="http://www.phpunit.de/manual/current/en/index.html">PHPUnit</a> , which is an additional PEAR package you have to install on the server. You can then use <a title="A series of mock functions to simulate WordPress for use with a unit testing framework" href="https://github.com/johnbintz/mockpress">MockPress</a> to simulate WordPress in the tests. Another option is the <a href="http://wordpress.org/extend/plugins/simpletest-for-wordpress/">SimpleTest for WordPress plugin</a> , which uses <a href="http://www.simpletest.org/">SimpleTest</a> instead of PHPUnit, doesn&#8217;t require installing a PEAR... [<a href="http://iandunn.name/unit-testing-wordpress-plugins/">more</a>]]]></description>
			<content:encoded><![CDATA[<p>Nikolay Bachiyski gave a good talk at this year&#8217;s WordCamp San Francisco about <a title="Unit Testing Will Change Your Life" href="http://wordpress.tv/2011/08/20/nikolay-bachiyski-unit-testing-will-change-your-life/">unit testing WordPress plugins</a>. His method uses <a href="http://www.phpunit.de/manual/current/en/index.html">PHPUnit</a>, which is an additional PEAR package you have to install on the server. You can then use <a title="A series of mock functions to simulate WordPress for use with a unit testing framework" href="https://github.com/johnbintz/mockpress">MockPress</a> to simulate WordPress in the tests.</p>
<p>Another option is the <a href="http://wordpress.org/extend/plugins/simpletest-for-wordpress/">SimpleTest for WordPress plugin</a>, which uses <a href="http://www.simpletest.org/">SimpleTest</a> instead of PHPUnit, doesn&#8217;t require installing a PEAR package, and lets you run both unit and  integration tests.</p>
<p>Either way, you can use PHP&#8217;s ReflectionClass to <a title="Best practices to test protected methods with PHPUnit" href="http://stackoverflow.com/questions/249664/best-practices-to-test-protected-methods-with-phpunit">test private and protected methods</a>, although purists will tell you <a title="Do you test private [methods]?" href="http://stackoverflow.com/questions/105007/do-you-test-private-method">that&#8217;s not proper</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/unit-testing-wordpress-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance Improvements for Dedicated WordPress Servers</title>
		<link>http://iandunn.name/performance-improvements-for-dedicated-wordpress-servers/</link>
		<comments>http://iandunn.name/performance-improvements-for-dedicated-wordpress-servers/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 20:45:14 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[PHP-APC]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=952</guid>
		<description><![CDATA[Mark Maunder <a title="The Basic WordPress Speedup" href="http://markmaunder.com/2011/the-basic-wordpress-speedup/">benchmarked several performance tuning measures</a> with a WordPress installation on a VPS server to show which are most effective. The biggest improvements were from installing <a href="http://php.net/manual/en/book.apc.php">PHP-APC</a> , setting up <a href="http://nginx.org/">Nginx</a> to proxy concurrent connections for Apache, and using MySQL&#8217;s query cache. &#160;]]></description>
			<content:encoded><![CDATA[<p>Mark Maunder <a title="The Basic WordPress Speedup" href="http://markmaunder.com/2011/the-basic-wordpress-speedup/">benchmarked several performance tuning measures</a> with a WordPress installation on a VPS server to show which are most effective. The biggest improvements were from installing <a href="http://php.net/manual/en/book.apc.php">PHP-APC</a>, setting up <a href="http://nginx.org/">Nginx</a> to proxy concurrent connections for Apache, and using MySQL&#8217;s query cache.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/performance-improvements-for-dedicated-wordpress-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing Multi-Dimensional Arrays from WordPress to JavaScript</title>
		<link>http://iandunn.name/passing-multi-dimensional-arrays-from-wordpress-to-javascript/</link>
		<comments>http://iandunn.name/passing-multi-dimensional-arrays-from-wordpress-to-javascript/#comments</comments>
		<pubDate>Sat, 23 Jul 2011 06:32:35 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Multi-Dimensional Arrays]]></category>
		<category><![CDATA[wp_localize_script]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=924</guid>
		<description><![CDATA[On its own <a href="http://codex.wordpress.org/Function_Reference/wp_localize_script">wp_localize_script()</a> can&#8217;t handle multi-dimensional arrays, but you can get around that by <a title="Passing PHP array to JavaScript using wp_localize_script()" href="http://www.ronakg.com/2011/05/passing-php-array-to-javascript-using-wp_localize_script/">encoding the child arrays in JSON</a> . That doesn&#8217;t handle HTML content very well, though, so another way to do it is to <a title="pass object/JSON to wp_localize_script" href="http://wordpress.stackexchange.com/questions/8655/pass-object-json-to-wp-localize-script">use the l10n_print_after parameter</a> . That&#8217;s kind of ugly, but it seems like the best way available right now. It looks like <a title="WordPress Trac ticket #11520" href="http://core.trac.wordpress.org/ticket/11520">WordPress 3.3 might have a wp_add_js_data() function</a> , which would be much... [<a href="http://iandunn.name/passing-multi-dimensional-arrays-from-wordpress-to-javascript/">more</a>]]]></description>
			<content:encoded><![CDATA[<p>On its own <a href="http://codex.wordpress.org/Function_Reference/wp_localize_script">wp_localize_script()</a> can&#8217;t handle multi-dimensional arrays, but you can get around that by <a title="Passing PHP array to JavaScript using wp_localize_script()" href="http://www.ronakg.com/2011/05/passing-php-array-to-javascript-using-wp_localize_script/">encoding the child arrays in JSON</a>. That doesn&#8217;t handle HTML content very well, though, so another way to do it is to <a title="pass object/JSON to wp_localize_script" href="http://wordpress.stackexchange.com/questions/8655/pass-object-json-to-wp-localize-script">use the l10n_print_after parameter</a>. That&#8217;s kind of ugly, but it seems like the best way available right now. It looks like <a title="WordPress Trac ticket #11520" href="http://core.trac.wordpress.org/ticket/11520">WordPress 3.3 might have a wp_add_js_data() function</a>, which would be much nicer.</p>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/passing-multi-dimensional-arrays-from-wordpress-to-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conditionally Loading JavaScript and CSS in WordPress Plugins</title>
		<link>http://iandunn.name/conditionally-loading-javascript-and-css-in-wordpress-plugins/</link>
		<comments>http://iandunn.name/conditionally-loading-javascript-and-css-in-wordpress-plugins/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 20:59:50 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Standards and Best Practices]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Shortcodes]]></category>

		<guid isPermaLink="false">http://iandunn.name/?p=887</guid>
		<description><![CDATA[When writing a WordPress plugin it&#8217;s considered a best practice to only include JavaScript/CSS/etc files on the specific pages that need them, rather than on every page load. This speeds up page load by reducing the number of HTTP transactions and also minimizes the risk of unnecessary conflicts between other files. There are two popular... [<a href="http://iandunn.name/conditionally-loading-javascript-and-css-in-wordpress-plugins/">more</a>]]]></description>
			<content:encoded><![CDATA[<p>When writing a WordPress plugin it&#8217;s considered a best practice to only include JavaScript/CSS/etc files on the specific pages that need them, rather than on every page load. This speeds up page load by reducing the number of HTTP transactions and also minimizes the risk of unnecessary conflicts between other files. There are two popular methods for achieving this for a shortcode.</p>
<p><a title="How to load JavaScript like a WordPress Master" href="http://scribu.net/wordpress/optimal-script-loading.html">The first method</a> sets a flag inside the shortcode handler when the shortcode is called, and then checks the flag in a wp_footer() callback. If the flag is true,  wp_print_scripts() is used output the JavaScript. The problem with this approach is that it doesn&#8217;t work for CSS, because CSS should be declared inside the head tag.</p>
<p><a title="How To Include CSS and JavaScript Conditionally And Only When Needed By The Posts" href="http://beerpla.net/2010/01/13/wordpress-plugin-development-how-to-include-css-and-javascript-conditionally-and-only-when-needed-by-the-posts/">The second method</a> &#8216;peeks ahead&#8217; by checking to see if the shortcode exists inside the current post&#8217;s content before wp_head() is called. This is much better because it works for CSS and allows you to use wp_enqueue_script(). The one problem with it, though, is that there&#8217;s no practical way to check if someone uses do_shortcode() in a template, rather than putting the shortcode in a post.</p>
<p><a title="Conditionally Loading JavaScript/CSS for Shortcodes" href="http://wordpress.stackexchange.com/questions/20854/conditionally-loading-javascript-css-for-shortcodes">The workaround for that</a> is to provide a way for a theme developer to tell the plugin which pages are calling do_shortcode(), so that the plugin will know to include the files on those pages too. You can do this by checking if the scripts are loaded in your shortcode handler, and then outputing an error if they&#8217;re not. The error can contain a link to instructions for them on how to provide the list of pages to the plugin.</p>
<p>I&#8217;ve implemented this in version 1.1.3 of <a href="http://wordpress.org/extend/plugins/basic-google-maps-placemarks/">Basic Google Maps Placemarks</a>, so you can download it or <a title="Source code for Basic Google Maps Placemarks version 1.1.3" href="http://plugins.svn.wordpress.org/basic-google-maps-placemarks/tags/1.1.3/">browse the source</a> to see it working in a live environment.</p>
<p>Here&#8217;s a stripped-down version of what&#8217;s happening on the  plugin side. loadResources() hooks in with a priority of 11 so that it loads after the theme&#8217;s code, and it calls mapShortcodeCalled() in order to check if it should load the files on the current page.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

if( !class_exists('BasicGoogleMapsPlacemarks') )
{
	/**
	* A WordPress plugin that adds a custom post type for placemarks and builds a Google Map with them
	* Requires PHP5+ because of various OOP features, json_encode(), pass by reference, etc
	* Requires WordPress 3.0 because of custom post type support
	*
	* @package BasicGoogleMapsPlacemarks
	* @author Ian Dunn &lt;redacted@iandunn.name&gt;
	* @link http://wordpress.org/extend/plugins/basic-google-maps-placemarks/
	*/
	class BasicGoogleMapsPlacemarks
	{
		// ...

		/**
		* Constructor
		* @author Ian Dunn &lt;redacted@iandunn.name&gt;
		*/
		public function __construct()
		{
			// ...

			$this-&gt;mapShortcodeCalled	= false;

			// ...

			add_action( 'wp_head',								array( $this, 'outputHead' ) );
			add_action( 'wp_footer',							array( $this, 'outputFooter' ) );
			add_filter( 'the_posts', 							array( $this, 'loadResources'), 11 );
			add_shortcode( 'bgmp-map',							array( $this, 'mapShortcode') );
		}

		/**
		* Checks the current post(s) to see if they contain the map shortcode
		* @author Ian Dunn &lt;redacted@iandunn.name&gt;
		* @param array $posts
		* @return bool
		*/
		function mapShortcodeCalled($posts)
		{
			$this-&gt;mapShortcodeCalled = apply_filters( self::PREFIX .'mapShortcodeCalled', $this-&gt;mapShortcodeCalled );
			if( $this-&gt;mapShortcodeCalled )
				return true;

			foreach( $posts as $p )
			{
				preg_match( '/'. get_shortcode_regex() .'/s', $p-&gt;post_content, $matches );
				if( is_array($matches) &amp;amp;amp;&amp;amp;amp; array_key_exists(2, $matches) &amp;amp;amp;&amp;amp;amp; $matches[2] == 'bgmp-map' )
					return true;
			}

			return false;
		}

		/**
		* Load CSS and JavaScript files
		* @author Ian Dunn &lt;redacted@iandunn.name&gt;
		*/
		public function loadResources($posts)
		{
			// @todo - maybe find an action that gets run at the same time. would be better to hook there than to a filter. update faq for do_shortcode if do

			wp_register_script(
				'googleMapsAPI',
				'http'. ( is_ssl() ? 's' : '' ) .'://maps.google.com/maps/api/js?sensor=false',
				false,
				false,
				true
			);

			wp_register_script(
				'bgmp',
				plugins_url( 'functions.js', __FILE__ ),
				array( 'googleMapsAPI', 'jquery' ),
				self::BGMP_VERSION,
				true
			);

			wp_register_style(
				self::PREFIX .'style',
				plugins_url( 'style.css', __FILE__ ),
				false,
				self::BGMP_VERSION,
				false
			);

			if( $posts )
			{
				$this-&gt;mapShortcodeCalled = $this-&gt;mapShortcodeCalled( $posts );

				if( !is_admin() &amp;amp;amp;&amp;amp;amp; $this-&gt;mapShortcodeCalled )
				{
					wp_enqueue_script('googleMapsAPI');
					wp_enqueue_script('bgmp');
				}

				if( is_admin() || $this-&gt;mapShortcodeCalled )
					wp_enqueue_style( self::PREFIX . 'style' );
			}

			return $posts;
		}

		/**
		* Outputs elements in the &lt;head&gt; section of the front-end
		* @author Ian Dunn &lt;redacted@iandunn.name&gt;
		*/
		public function outputHead()
		{
			if( $this-&gt;mapShortcodeCalled )
			require_once( dirname(__FILE__) . '/views/front-end-head.php' );
		}

		/**
		* Outputs some initial values for the JavaScript file to use
		* @author Ian Dunn &lt;redacted@iandunn.name&gt;
		*/
		public function outputFooter()
		{
			if( $this-&gt;mapShortcodeCalled )
			require_once( dirname(__FILE__) . '/views/front-end-footer.php' );
		}

		/**
		* Defines the [bgmp-map] shortcode
		* @author Ian Dunn &lt;redacted@iandunn.name&gt;
		* @param array $attributes Array of parameters automatically passed in by WordPress
		* return string The output of the shortcode
		*/
		public function mapShortcode($attributes)
		{
			if( !wp_script_is( 'googleMapsAPI', 'queue' ) || !wp_script_is( 'bgmp', 'queue' ) || !wp_style_is( self::PREFIX .'style', 'queue' ) )
				return '&lt;p class=&quot;error&quot;&gt;'. BGMP_NAME .' error: JavaScript and/or CSS files aren\'t loaded. If you\'re using do_shortcode() you need to add a filter to your theme first. See &lt;a href=&quot;http://wordpress.org/extend/plugins/basic-google-maps-placemarks/faq/&quot;&gt;the FAQ&lt;/a&gt; for details.&lt;/p&gt;';

			$output = sprintf('
				&lt;div id=&quot;%smap-canvas&quot;&gt;
				&lt;p&gt;Loading map...&lt;/p&gt;
				&lt;p&gt;&lt;img src=&quot;%s&quot; alt=&quot;Loading&quot; /&gt;&lt;/p&gt;
				&lt;/div&gt;',
				self::PREFIX,
				plugins_url( 'images/loading.gif', __FILE__ )
			);

			return $output;
		}

		// ...

	} // end BasicGoogleMapsPlacemarks
}

?&gt;
</pre>
<p>The theme developer can put this code in their functions.php file to tell the plugin which pages to load the files on:</p>
<pre class="brush: php; title: ; notranslate">
add_filter( 'the_posts', 'my_theme_name_bgmp_shortcode_check' );
function my_theme_name_bgmp_shortcode_check( $posts )
{
	$shortcodePageSlugs = array(
		'first-page-slug',
		'second-page-slug',
		'hello-world'
	);

	if( $posts )
		foreach( $posts as $p )
			if( in_array( $p-&gt;post_name, $shortcodePageSlugs ) )
				add_filter( 'bgmp_mapShortcodeCalled', 'your_theme_name_bgmp_shortcode_called' );

	return $posts;
}

function your_theme_name_bgmp_shortcode_called( $mapShortcodeCalled )
{
	return true;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/conditionally-loading-javascript-and-css-in-wordpress-plugins/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

