<?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>Digging into WordPress &#187; optimization</title>
	<atom:link href="http://digwp.com/tag/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:03:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Optimizing WordPress Permalinks</title>
		<link>http://digwp.com/2010/07/optimizing-wordpress-permalinks/</link>
		<comments>http://digwp.com/2010/07/optimizing-wordpress-permalinks/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 08:45:19 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[permalink]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2026</guid>
		<description><![CDATA[Configuring your WordPress permalinks is simple and only takes a second, but understanding what they are and how they work is key to setting up the best permalink structure possible. Your site&#8217;s permalinks are like the street address for your site&#8217;s web pages. They help both people and robots understand your site&#8217;s structure and navigate [...]]]></description>
			<content:encoded><![CDATA[<p>Configuring your <strong>WordPress permalinks</strong> is simple and only takes a second, but understanding what they are and how they work is <em>key</em> to setting up the <strong>best permalink structure possible</strong>. Your site&rsquo;s permalinks are like the street address for your site&rsquo;s web pages. They help both people and robots understand your site&rsquo;s structure and navigate its contents. There is no &ldquo;one magic permalink recipe to rule them all,&rdquo; but keeping a few tips in mind makes it <em>easy</em> to <strong>optimize your WordPress permalinks</strong>. This <abbr title="Digging into WordPress">DiW</abbr> article shows you how..</p>
<p><span id="more-2026"></span></p>
<h3>WordPress makes it <em>so</em> easy</h3>
<p>WordPress gives you full control over your permalinks. First, you have control over the <em>general structure</em> of your permalinks. Navigate to <strong>Settings &gt; Permalinks</strong> and you will see several options for configuring your permalinks:</p>
<p><img src="http://digwp.com/wp-content/blog-images/optimize-permalinks-setting.gif" alt="[ Screenshot: WP Permalink Settings ]" title="WordPress provides control over the general structure of your permalinks" /></p>
<p>This is where you configure the general structure of your permalinks, as seen here with green underline. The portion underlined in red is post/page-specific, and will vary depending on your individual posts and pages. For <a href="http://digwp.com/" title="Digging into WordPress">DigWP.com</a>, we chose the &ldquo;month and name&rdquo; format, which creates the following permalinks according to page-view:</p>
<ul>
<li><strong>Pages</strong> &rarr; <code>http://digwp.com/about/</code></li>
<li><strong>Tag Archives</strong> &rarr; <code>http://digwp.com/tag/permalinks/</code></li>
<li><strong>Category Archives</strong> &rarr; <code>http://digwp.com/category/seo/</code></li>
<li><strong>Single Posts</strong> &rarr; <code>http://digwp.com/2010/05/wordpress-json-api-plugin/</code></li>
</ul>
<p>..and so on. The main thing that you want to optimize at this point is the structure of your single-post permalinks. We chose to include the year and month for our posts, but it has been argued that it is better to omit the date entirely, using a &ldquo;Custom structure&rdquo; like so:</p>
<p><code>/%postname%/</code></p>
<p>This simple structure will produce single-post permalinks that include only the post name:</p>
<p><code>http://digwp.com/wordpress-json-api-plugin/</code></p>
<p>Without the additional date information, this structure is definitely shorter and cleaner, but there may be <a href="http://dougal.gunters.org/blog/2009/02/04/efficient-wordpress-permalinks" title="Efficient permalink strategies for WordPress">performance issues involved with using the &ldquo;name-only&rdquo; permalink format</a>. Perhaps a good trade-off is to include either the post ID or the year:</p>
<pre><code>/%post_id%/%postname%/
/%year%/%postname%/</code></pre>
<p>I think either of these formats is probably an optimal way to configure your permalinks, but you also want to consider the frequency with which you&rsquo;ll be posting content. It may be beneficial to further organize/classify your posts by including the month and day as well. </p>
<p>Certain &ldquo;experts&rdquo; will tell you that including extraneous date information is bad for <acronym title="Search Engine Optimization">SEO</acronym>. The thinking here is that shorter <acronym title="Uniform Resource Locator">URL</acronym>s correspond to a more &ldquo;flat&rdquo; directory structure, which <a href="http://www.seomoz.org/blog/whiteboard-friday-flat-site-architecture" title="Whiteboard Friday - Flat Site Architecture">may provide some SEO benefits</a>. I think the key is to use what&rsquo;s necessary and omit any extraneous information.</p>
<h3>Post/page-specific permalink structures (slugs!)</h3>
<p>Once you&rsquo;ve defined the <em>general</em> permalink structure in the WordPress Admin, you now have full control over your post-specific and page-specific permalink structures (as seen in the above screenshot, red underline). The part of your permalinks that is specific to each page or post is set in the <strong>Write/Edit Post</strong> screen in the WordPress Admin.</p>
<p><img src="http://digwp.com/wp-content/blog-images/optimize-permalinks-slugs.gif" alt="[ Screenshot: WordPress Post Slugs ]" /></p>
<p>As shown in the above screenshot, WordPress provides an &ldquo;Edit&rdquo; button that enables you to modify the post-specific portion of your permalinks:</p>
<p><img src="http://digwp.com/wp-content/blog-images/optimize-permalinks-slugs-e.gif" alt="[ Screenshot: Editing Post Slugs ]" /></p>
<p>This feature enables you to customize your post/page-specific permalinks (also known as a post &ldquo;slug&rdquo;) according to your current permalink optimization strategy. Here are a few examples of commonly employed &ldquo;post-slug&rdquo; strategies:</p>
<dl>
<dt>Don&rsquo;t even worry about it</dt>
<dd>Just let WordPress generate the post-specific slug based on the post or page title. Pros: this is certainly the easiest method of creating permalinks because no thought or action is required. Cons: depending on your post title, you could get some pretty long permalinks that look awkward and sloppy.</dd>
<dt>Remove extraneous words, leave only keywords</dt>
<dd>I have seen lots of blogs do this. It basically involves using the permalink that WordPress generates based on your title, then going in and removing words like &ldquo;the&rdquo;, &ldquo;and&rdquo;, and &ldquo;you&rdquo;, as well as other pronouns and such. Basically the idea is to leave only keywords in your permalinks. This helps keep them short, focused, and optimized for the search engines.</dd>
<dt>Customize every permalink with optimized keywords</dt>
<dd>This is the most labor-intensive strategy, but also potentially the most lucrative in terms of return on investment. The idea here is to research or otherwise understand which keywords your page is going to rank for, and then crafting a post-specific permalink structure based on those keywords. I have seen cases where this is taken to such an extreme that the post slug is completely different than the original post title.</dd>
</dl>
<p>The same goes for both posts and pages, regardless of which method you choose. Personally, I employ a combination of the first two strategies, whereby I go in, write a title, and then look at it and see if there is anything that could be improved. Usually there are several words that need to go, and possibly a keyword or two is added or removed. It&rsquo;s funny because I usually end up rewriting some of the post content after spending some time actually thinking about what to name it. </p>
<blockquote><p>There is always a better title than the one you think should be used.</p></blockquote>
<p>The take-home message here is that, by paying attention to post titles and permalinks, you benefit from improved relevancy and potential <acronym title="Search Engine Optimization">SEO</acronym> advantage.</p>
<h3>Think of your users</h3>
<p>When visitors land on your page, does the <acronym title="Uniform Resource Locator">URL</acronym> make sense? Does it correlate with the page title? These are some of the things to think about while setting up the general structure and post-specific slugs for your permalinks. Look at the permalink and ask yourself if it makes complete sense based on what the user will be looking at on the page. If you get too carried away with optimization, a user may get a sense that something isn&rsquo;t quite right. Perhaps the post title says something like:</p>
<p><strong>The Best Name-Brand Shoes</strong></p>
<p>..but then the post slug looks something like this:</p>
<p><code>http://example.com/nike-adidas-reebok-zip-converse-shoes/</code></p>
<p>Perhaps a weak example, but it serves to illustrate the semantic gap that may occur when over-thinking your permalinks.</p>
<h3>Think of the search engines</h3>
<p><em>After</em> considering your users, think about what the search engines are going to see when they come crawling your pages. Does the permalink match the content of the page? If you aren&rsquo;t bothering with changing or optimizing your post slugs, then the answer is probably yes because WordPress generates the slug from the post title.</p>
<p>Also, as mentioned previously, some have argued in favor of a more &ldquo;flat&rdquo; directory structure in order to improve the <acronym title="Search Engine Optimization">SEO</acronym> value of your blog. Whether or not this is actually the case is up for discussion, but it always makes sense to keep things as simple and concise as possible. So when deciding on the general structure for your permalinks, ask yourself if you really need a directory structure that is over three levels deep, like this:</p>
<pre><code>domain/
	2010/
	      01/
		  1/
			post-slug-1
			post-slug-2
			post-slug-3
		  2/
			post-slug-4
			post-slug-5
			post-slug-6
		  3/
			post-slug-7
			post-slug-8
			post-slug-9
	      .
	      .
	      .
	2011/
	2012/</code></pre>
<p>That&rsquo;s going to give you some <em>long</em> permalinks, especially if you just use the default WordPress-generated slugs. When you look at a permalink using &ldquo;<code>year/month/name</code>&rdquo; format, you are essentially creating a virtual folder structure with a subdirectory for each part of the permalink &ndash; the year represents a directory in which you have a bunch of directories for each month, and within each of those directories there could be as many as 31 subdirectories for each day of the month. Then, within each day of the month, you have the post file itself, which may involve further subdirectories when paging is used. It can get crazy pretty quickly, and even though these subdirectories only exist virtually, to a search spider, there is no practical difference between <em>virtual</em> directories that are deeply nested and <em>actual</em> directories that are deeply nested.</p>
<p>When deciding on your permalink structure, ask yourself if you really need the date built into your permalinks. If you are posting prolifically, then you may want to include the date to help keep things organized. Anything less than a few posts a week, and I would opt to go with something simpler, like maybe &ldquo;<code>year/post</code>&rdquo; or &ldquo;<code>id/post</code>&rdquo;, as mentioned above.</p>
<p>Another thing that needs considering is the notion of &ldquo;evergreen content&rdquo;, which generally refers to content that is intended to stay &ldquo;fresh&rdquo; or relevant forever. Regardless how silly this <acronym title="Search Engine Optimization">SEO</acronym> idea happens to be, you may want to consider either omitting or including some sort of date information based on how easily you want the publication date to be recognized by your visitors. I.e., if you are trying to &ldquo;hide&rdquo; the post date in hopes that your content will rank for a longer period of time, then you should omit it from the general permalink structure. Conversely, if you aren&rsquo;t that slimy and want to make it easy for people to know when the post was produced, then throw a year or year/month into the mix. Whatever!</p>
<h3>Think simplicity</h3>
<p>When it comes to organizing the content of your site, <strong>there is a fine balance</strong> between being <em>well-organized</em> and keeping things <em>simple</em>. For example, the simplest structure would involve all posts and pages directly under the root domain. Clean and simple, but as time goes on and your post count gets into the hundreds or thousands, it could be a drag trying to sort through everything in a flat directory structure. Thus, another reason why breaking things down into categories or dates may help your long-term organizational and maintenance strategy.</p>
<p>For the post-specific portion of the permalinks (the post slug), it is also wise to keep things simple, but not at the risk of duplicating post names. For example, if you are writing a post about jQuery, you might have a post slug that is simply &ldquo;<code>jquery</code>&rdquo;, but it&rsquo;s not going to be very helpful. First, it probably will never rank for that term. Second, telling users that the article is about &ldquo;jQuery&rdquo; is about as useless as it gets for both people <em>and</em> machines. So although that would be the simplest permalink possible, it is your interest to specify a little more clearly the content of your post. It just makes everything easier when meaning is readily available from your permalinks.</p>
<h3>Do it <em>before</em> posting</h3>
<p>Once you hit the &ldquo;Publish&rdquo; button, there is <strong>one</strong> thing that you shouldn&rsquo;t change: the post slug. After publishing a post, you can easily and without consequence go back and change the title, meta title, post content, and just about everything else. But as soon as you change that permalink, you will need to 301 redirect the former <acronym title="Uniform Resource Locator">URL</acronym> to the new one in order to avoid perpetual 404 errors now and in the future. But, if you do need to change the permalink <em>after</em> posting, here is a simple line of <acronym title="Hypertext Access">HTAccess</acronym> to help you eliminate any potential 404 errors:</p>
<pre><code>Redirect 301 /old-post-slug/ http://example.com/new-post-slug/</code></pre>
<p>So it&rsquo;s really very simple: we first call the redirect directive, declare it as status 301 (permanent), and then add the old slug followed by the new one. That line will redirect any requests for your previously &ldquo;slugged&rdquo; <acronym title="Uniform Resource Locator">URL</acronym> to your new <acronym title="Uniform Resource Locator">URL</acronym>. For more information on htaccess redirects, check <a href="http://perishablepress.com/press/2008/12/31/redirect-all-broken-links-from-any-domain-via-htaccess/" title="Redirect All (Broken) Links from any Domain via HTAccess">here</a> and <a href="http://perishablepress.com/press/2008/08/12/redirect-all-requests-for-a-nonexistent-file-to-the-actual-file/" title="Redirect All Requests for a Nonexistent File to the Actual File">here</a>.</p>
<h3>Think of the keywords</h3>
<p>As discussed, a great way to create focused, relevant permalinks is to remove the fluff and include only the important keywords. Granted, Google et al may already discount simple words such as &ldquo;if&rdquo;, &ldquo;and&rdquo;, and &ldquo;the&rdquo;, but you may also have keywords for which you don&rsquo;t necessarily want to rank. For example, if you published a post on why Batman is terrible at website design, you may wind up with a auto-generated post slug like this:</p>
<p><code>batman-sucks-at-website-design</code></p>
<p>The word &ldquo;at&rdquo; should probably go, leaving this:</p>
<p><code>batman-sucks-website-design</code></p>
<p>But you may want to rank primarily for the term &ldquo;website-design&rdquo;, while &ldquo;batman&rdquo; is merely anecdotal, used as example, or whatever. Chances are low that anybody is searching for &ldquo;batman website design&rdquo;, but you never know.</p>
<h3>WordPress removes stuff too</h3>
<p>It should also be noted that WordPress removes certain things from your post/page slugs as well. Namely, any punctuation that is included in your post titles will be removed when WordPress automatically generates the post slug. This is both a good thing and a bad thing, depending on how you look at it. There are certain characters that are not allowed in <em>any</em> <acronym title="Uniform Resource Locator">URL</acronym>, so WordPress is wise to remove them for you. On the downside, removal of punctuation and the use of hyphens as replacements for periods can leave you with some rather odd-looking permalinks. For example, when writing about the latest WordPress update, say version 3.1 specifically, writing this as your title:</p>
<p><code>Introducing WordPress 3.1</code></p>
<p>..will give you this as the default post slug:</p>
<p><code>/introducing-wordpress-3-1/</code></p>
<p>..which to me just looks incorrect, like somebody wasn&rsquo;t paying attention. Moral of the story: even if you&rsquo;re too lazy to optimize your permalink slugs, it is <em>wise to be mindful</em> of what&rsquo;s going on with the auto-generated stuff. In this regard, the WordPress devs made an excellent decision when they decided to move the permalink edit box to just below the post title. I do think it could be a little longer though. Most of the time you need to scroll sideways a bit to see what the entire permalink is looking like.</p>
<h3>WordPress short URLs</h3>
<p>What about Twitter-friendly &ldquo;shortlinks&rdquo; for your posts? Generally even the shortest permalink is going to be too long for tweeting, posting, sharing, etc. There are <a href="http://perishablepress.com/press/2009/10/18/stupid-twitter-tricks/" title="Stupid Twitter Tricks">many ways to create short links</a>, but WordPress actually has <em>two</em> built-in ways to create and display short <acronym title="Uniform Resource Locator">URL</acronym>s. Let&rsquo;s take a look at each:</p>
<p>First is the &ldquo;old&rdquo; way of doing it. By default, WordPress uses a query-string format for your <acronym title="Uniform Resource Locator">URL</acronym>s. As discussed throughout this article, most WordPress users opt for the &ldquo;pretty&rdquo; permalinks instead of going with the &ldquo;ugly&rdquo; default <acronym title="Uniform Resource Locator">URL</acronym>s. But even when permalinks are used, WordPress still understands the default query-string <acronym title="Uniform Resource Locator">URL</acronym> structure, so you can include short links in your posts by doing something like this:</p>
<pre><code>&lt;?php echo get_bloginfo('url')."/?p=".$post-&gt;ID; ?&gt;</code></pre>
<p>Shortlinks have become so common that <a href="http://codex.wordpress.org/Function_Reference/the_shortlink" title="Function Reference/the shortlink">WordPress 3.0 now includes</a> a built-in template tag for this very purpose. All you need to display shortlinks in WordPress 3 and above is include the following code in your theme template file(s):</p>
<p><code>&lt;?php the_shortlink('link text', 'link title', 'before link', 'after link'); ?&gt;</code></p>
<p>Either of these methods will output a link with the following <acronym title="Uniform Resource Locator">URL</acronym> structure:</p>
<p><code>http://example.com/?p=77</code></p>
<p>Also note that WordPress 3.0 now includes a shortlink in the <code>&lt;head&gt;</code> section of your posts and pages, something like this:</p>
<p><code>&lt;link rel='shortlink' href='http://example.com/?p=77' /&gt;</code></p>
<p>This is in <em>addition</em> to the canoncial link tag that is also included in the <code>&lt;head&gt;</code> section.</p>
<h3>WordPress canonical links</h3>
<p>WordPress canonical <acronym title="Uniform Resource Locator">URL</acronym>s are included in the <code>&lt;head&gt;</code> section of your posts and pages. They look like this:</p>
<p><code>&lt;link rel='canonical' href='http://example.com/post-slug/' /&gt;</code></p>
<p>These canonical links help the search engines better understand the structure and content of your site. By including the canoncial element in your pages, you are telling Google et al which pages are <em>the</em> actual, canonical pages for your site. There are several cases where this is extremely helpful, namely:</p>
<ul>
<li>Social media linking often involves shortlinks &ndash; specifying a canonical link helps ensure that all of the shortlinking is sorted out and that your actual page gets the credit</li>
<li>Shopping cart sites that feature lots of query-string <acronym title="Uniform Resource Locator">URL</acronym>s &ndash; when many links look practically identical, having a canonical link specified helps to sort things out</li>
<li>Guest posting and other duplicate content &ndash; when your content is featured (or scraped) in multiple places around the Web, it is nice to have a clear signal as to which case is canonical</li>
</ul>
<h4>You don&#8217;t need htaccess to make changes</h4>
<p>What if you want to change the <em>general</em> structure of your permalinks? How do you go about doing that without losing your page rank while creating a mess of 404 errors? In older versions of WordPress, this was a real concern. Many folks began with full-date permalinks and then later realized they wanted cleaner, shorter, &ldquo;dateless&rdquo; permalinks instead. To do this back in the day, some <a href="http://perishablepress.com/press/2008/02/06/permalink-evolution-customize-and-optimize-your-dated-wordpress-permalinks/" title="Permalink Evolution: Customize and Optimize Your Dated WordPress Permalinks">HTAccess trickery</a> was required to keep the old links from going nowhere. </p>
<p>Fortunately those days are long gone, as WordPress now automagically handles all the redirecting for you when making changes to the <strong>general structure</strong> of your permalinks (via the <strong>Settings &gt; Permalinks</strong> options in the WordPress Admin). All you need to do is change the setting to whatever structure you would like and WordPress takes care of the rest. Just remember to backup your database and htaccess file before making any changes.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/07/optimizing-wordpress-permalinks/">Permalink</a> | <a href="http://digwp.com/2010/07/optimizing-wordpress-permalinks/#comments">38 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/07/optimizing-wordpress-permalinks/&title=Optimizing WordPress Permalinks">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/optimization/" rel="tag">optimization</a>, <a href="http://digwp.com/tag/permalink/" rel="tag">permalink</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/07/optimizing-wordpress-permalinks/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Optimizing WordPress Post Navigation</title>
		<link>http://digwp.com/2009/12/optimizing-wordpress-post-navigation/</link>
		<comments>http://digwp.com/2009/12/optimizing-wordpress-post-navigation/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 06:20:55 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[posts]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1058</guid>
		<description><![CDATA[Implementing a solid set of navigational links for your WordPress site is one of the best ways to encourage visitors to stick around awhile and check out additional content. As discussed in our definitive guide to WordPress post navigation, there are essentially three different types of navigational tags for WordPress: Index and archive navigation: posts_nav_link() [...]]]></description>
			<content:encoded><![CDATA[<p>Implementing a solid set of navigational links for your WordPress site is one of the best ways to encourage visitors to stick around awhile and check out additional content. As discussed in our <a href="http://digwp.com/2009/08/wordpress-page-navigation/" title="Definitive Guide to WordPress Page Navigation">definitive guide to WordPress post navigation</a>, there are essentially three different types of navigational tags for WordPress:</p>
<ul>
<li>Index and archive navigation: <a href="http://digwp.com/2009/08/wordpress-page-navigation/#postsnavlink" title="posts_nav_link()">posts_nav_link()</a></li>
<li>Index and archive navigation: <a href="http://digwp.com/2009/08/wordpress-page-navigation/#previouspostslink" title="previous_posts_link() and next_posts_link()">previous_posts_link() and next_posts_link()</a></li>
<li>Single-view posts navigation: <a href="http://digwp.com/2009/08/wordpress-page-navigation/#previouspostlink" title="previous_post_link() and next_post_link()">previous_post_link() and next_post_link()</a></li>
</ul>
<p>Without repeating ourselves, suffice it to say that <code>previous_posts_link</code> and <code>next_posts_link</code> are perfect for setting up separate links for index, category, and archive pages. Likewise, <code>previous_post_link</code> and <code>next_post_link</code> are perfect for setting up separate links for single-view post navigation.</p>
<p>Now that we&rsquo;re on the same page, so to speak, let&rsquo;s look at how these tags are typically used and how to improve and optimize their functionality..</p>
<p><span id="more-1058"></span></p>
<h3>Improving the <code>next_posts_link</code> and <code>previous_posts_link</code> (for archive views)</h3>
<p>Here are the archive/category navigation links as provided in the default theme that is packaged with WordPress:</p>
<pre><code>&lt;div class="navigation"&gt;
	&lt;div class="alignleft"&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt;
	&lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>Functionally, this setup works great &#8212; the previous-post link is displayed <em>only</em> when there are previous posts, and likewise the next-post link is displayed <em>only</em> when there are newer posts. As convenient as this is, it doesn&rsquo;t help us with the accompanying markup used to display the links. Any <acronym title="Cascading Style Sheets">CSS</acronym> styles applied to the <code>&lt;div&gt;</code>s in our example will be displayed even when the links themselves aren&rsquo;t displayed. This can result in several issues, including:</p>
<ul>
<li>Padding and margins may prevent proper display when links are missing</li>
<li>Background images used to enhance the navigational links will still be displayed</li>
<li>Additional text and/or characters will still be displayed even when links absent</li>
<li>Use of any markup other than <code>&lt;div&gt;</code>s may result in validation errors when left empty</li>
</ul>
<p>And we&rsquo;re not just talking about the front page and last page here &#8212;  any category, tag, search, date, or author archive will also display botched navigational elements and design flaws when previous and next posts are unavailable. Your main index may always have previous posts, but what about that guest author archive, 2005 archive, and search results? Such pages are frequently one of a kind. Even worse, by defualt, your Home page will <em>never</em> have a page after it, which means a broken navigational element right there on the most important page of your site. Not good.</p>
<p>The easiest way that I have found to prevent this from happening when the &ldquo;next&rdquo; link is not generated is to simply test the <code>$paged</code> variable for a value greater than <code>1</code>:</p>
<pre><code>&lt;?php if ($paged &gt; 1) { ?&gt;

	&lt;div class="navigation"&gt;
		&lt;div class="alignleft"&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt;
		&lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/div&gt;
	&lt;/div&gt;

&lt;?php } ?&gt;</code></pre>
<p>By checking if there are more posts to display before calling the navigational code, this technique will prevent empty elements from wrinkling your home page and archive pages. Another way of doing this is shared by <a href="http://www.ericmmartin.com/conditional-pagepost-navigation-links-in-wordpress-redux/" title="Conditional page/post navigation links in WordPress (redux)">Eric Martin</a>. Just place this snippet into your active theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>// return TRUE if more than one page exists
function show_posts_nav() {
	global $wp_query;
	return ($wp_query-&gt;max_num_pages &gt; 1);
}</code></pre>
<p>And then use the function to conditionally display navigational code in your <code>archive.php</code> and other archive-view template files:</p>
<pre><code>&lt;?php if (show_posts_nav()) : ?&gt;

	&lt;div class="navigation"&gt;
		&lt;div class="alignleft"&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt;
		&lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/div&gt;
	&lt;/div&gt;

&lt;?php endif; ?&gt;</code></pre>
<p>Not sure if there is any benefit to adding the extra code in the <code>functions.php</code> file, but I thought I would share that technique with you as another possible solution (hey you never know).</p>
<p>Also, a great way to improve the functionality and presentation of your blog is to provide some alternate navigational elements to help keep things flowing and balanced on the front pages of your site. For example, at <a href="http://perishablepress.com/" title="Digital Design and Dialogue">Perishable Press</a>, if the &ldquo;next&rdquo; link isn&rsquo;t displayed, I provide a link to my site Archives:</p>
<pre><code>&lt;?php if ($paged &gt; 1) { ?&gt;

	&lt;div class="navigation"&gt;
		&lt;div class="alignleft"&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt;
		&lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/div&gt;
	&lt;/div&gt;

&lt;?php } else { ?&gt;

	&lt;div class="navigation"&gt;
		&lt;div class="alignleft"&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt;
		&lt;div class="alignright"&gt;&lt;a href="http://perishablepress.com/press/archives/"&gt;Site Archives &amp;raquo;&lt;/a&gt;&lt;/div&gt;
	&lt;/div&gt;

&lt;?php } ?&gt;</code></pre>
<p>And of course, anything is possible here; the key is to keep things consistent, logical, and well-styled. Now let&rsquo;s see how to improve navigational display for single-post views.</p>
<h3>Improving the <code>next_post_link</code> and <code>previous_post_link</code> (for single views)</h3>
<p>Fortunately, the situation is much improved for single-post navigation. By default, the <code>next_post_link</code> and <code>previous_post_link</code> provide parameters that enable us to avoid the &ldquo;empty-element&rdquo; syndrome. Let&rsquo;s take a look at these parameters:</p>
<p><code>&lt;?php next_post_link('format','link','in_same_cat','excluded_categories'); ?&gt;</code><br />
<code>&lt;?php previous_post_link('format','link','in_same_cat','excluded_categories'); ?&gt;</code></p>
<p>The <code>format</code> and <code>link</code> parameters enable us to do something like this:</p>
<pre><code>&lt;div class="navigation"&gt;

	&lt;?php previous_post_link('&lt;div class="alignleft"&gt;Previous entry: %link&lt;/div&gt;', '%title'); ?&gt;
	&lt;?php next_post_link('&lt;div class="alignright"&gt;Next entry: %link&lt;/div&gt;', '%title'); ?&gt;

&lt;/div&gt;</code></pre>
<p>Here we have replicated the markup in our previous examples, but have done so conditionally, such that the markup will only be displayed when the corresponding link is displayed, thereby enabling us to avoid empty elements when either the previous or next post-link is not displayed. As you can see, the single-post nav tags enable us to include the surrounding <acronym title="(eXtensible) Hypertext Markup Language">(X)HTML</acronym> and text <em>within</em> the function itself. We can do similar tricks with the actual link title. Check out our <a href="http://digwp.com/2009/08/wordpress-page-navigation/" title="Definitive Guide to WordPress Page Navigation">definitive guide to post navigation</a> for more information.</p>
<h3>Conditional navigational display for single posts</h3>
<p>Just as we did with the archive nav tags (<code>next_posts_link</code> and <code>previous_posts_link</code>), we can implement some conditional functionality to display alternate navigational links when viewing the first and last posts in any archive view. For example, if I also wanted to provide a link to my Site Archives when the &ldquo;next&rdquo; and/or &ldquo;previous&rdquo; links were <strong>not</strong> displayed, I could do so using the following code:</p>
<pre><code>&lt;div class="navigation"&gt;

	&lt;?php previous_post_link('&lt;div class="alignleft"&gt;Previous entry: %link&lt;/div&gt;', '%title'); ?&gt;
	&lt;?php if(!get_adjacent_post(false, '', true)) { 
		echo '&lt;div class="alignleft"&gt;&lt;a href="http://perishablepress.com/press/archives/"&gt;Site Archives&lt;/a&gt;&lt;/div&gt;'; 
	} ?&gt;

	&lt;?php next_post_link('&lt;div class="alignright"&gt;Next entry: %link&lt;/div&gt;', '%title'); ?&gt;
	&lt;?php if(!get_adjacent_post(false, '', false)) { 
		echo '&lt;div class="alignright"&gt;&lt;a href="http://perishablepress.com/press/archives/"&gt;Site Archives&lt;/a&gt;&lt;/div&gt;'; 
	} ?&gt;

&lt;/div&gt;</code></pre>
<p>Here we are using the <code>get_adjacent_post</code> function to determine whether or not there is a post before/after the current post. This enables us to conditionally display some sort of fallback navigation in the first- and last-post case. The <code>get_adjacent_post</code> tag accepts the following parameters:</p>
<ul>
<li><code>$in_same_cat</code> &ndash; specifies whether or not the adjacent post should be in the same category</li>
<li><code>$excluded_categories</code> &ndash; a comma-delimited list of categories for which the adjacent post should not belong</li>
<li><code>$previous</code> &ndash; specifies whether the previous post should be displayed</li>
</ul>
<p>That does it for the single-post views. Let&rsquo;s wrap things up with a way to consolidate and streamline the single and archive navigational methods..</p>
<h3>Optimize your theme&rsquo;s navigational code</h3>
<p>Finally, here is a nice way to clean up your theme files and source code. The first step is to streamline production by <a href="http://digwp.com/2009/07/getting-more-fine-grained-with-includes/" title="Getting More Fine-Grained with Includes">getting more fine-grained with includes</a>. This basically means that you can clean things up and save time/effort by moving your navigational code to its own file, named something like &ldquo;<code>navigation.php</code>&rdquo; or similar. You would then remove your nav code from your other template files and consolidate them all into that one location. You would then include <code>navigation.php</code> in any theme file where you want the navigation section to appear:</p>
<pre><code>&lt;?php include_once("navigation.php"); ?&gt;</code></pre>
<p>This technique makes maintaining and modifying your code a breeze. And, you can even streamline things further by using some conditional logic to display either <em>archive</em> or <em>single</em> navigation depending on the current page being viewed:</p>
<pre><code>&lt;?php if (is_single()) : ?&gt;

	&lt;div class="navigation"&gt;
		&lt;?php previous_post_link('&lt;div class="alignleft"&gt;Previous entry: %link&lt;/div&gt;', '%title'); ?&gt;
		&lt;?php next_post_link('&lt;div class="alignright"&gt;Next entry: %link&lt;/div&gt;', '%title'); ?&gt;
	&lt;/div&gt;

&lt;?php else : ?&gt;

	&lt;div class="navigation"&gt;
		&lt;div class="alignleft"&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt;
		&lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/div&gt;
	&lt;/div&gt;

&lt;?php endif; ?&gt;</code></pre>
<p>This is a great way of staying organized and reducing your workload during theme development and maintenance.</p>
<h3>Wrap up</h3>
<p>The tips and tricks in this article will help you create a consistent, logical, and design-friendly set of navigational links for your next theme design. In the process, you can also streamline production by consolidating your code into a single file and using conditional logic to deliver the appropriate code.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/12/optimizing-wordpress-post-navigation/">Permalink</a> | <a href="http://digwp.com/2009/12/optimizing-wordpress-post-navigation/#comments">10 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/12/optimizing-wordpress-post-navigation/&title=Optimizing WordPress Post Navigation">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/navigation/" rel="tag">navigation</a>, <a href="http://digwp.com/tag/optimization/" rel="tag">optimization</a>, <a href="http://digwp.com/tag/posts/" rel="tag">posts</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/12/optimizing-wordpress-post-navigation/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Mastering WordPress Post-Revisioning and Auto-Save Features</title>
		<link>http://digwp.com/2009/07/mastering-wordpress-post-revisioning-and-auto-save-features/</link>
		<comments>http://digwp.com/2009/07/mastering-wordpress-post-revisioning-and-auto-save-features/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 06:06:25 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[editing]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=344</guid>
		<description><![CDATA[Not everyone loves the post-revisioning feature of WordPress. In fact, some people can&#8217;t stand it. On the one hand, it&#8217;s nice to have a library of post-draft revisions to drudge through if you should ever make a mistake. On the other hand, multiple copies of every post is a great way to bloat your database [...]]]></description>
			<content:encoded><![CDATA[<p>Not everyone <em>loves</em> the post-revisioning feature of WordPress. In fact, some people can&rsquo;t stand it. On the one hand, it&rsquo;s nice to have a library of post-draft revisions to drudge through if you should ever make a mistake. On the other hand, multiple copies of <em>every</em> post is a great way to bloat your database with otherwise useless information. </p>
<p>Then, to complicate matters, WordPress&rsquo; auto-save functionality seems to have a mind of its own, at times interfering in the revisioning process even when post-revisioning has been disabled. Taken together, these post-revisioning and auto-save features have been known to confuse and frustrate WordPress users.</p>
<p>In this article, I explain how to take full control of WordPress&rsquo; version-revision and auto-save functionality. We&rsquo;ll explore how these features work, why they don&rsquo;t, when they clash, and how to stop the madness once and for all. </p>
<p><span id="more-344"></span></p>
<h3>WordPress AutoSave Feature</h3>
<p>WordPress implemented the AutoSave feature in version 2.1. Its function is to periodically (every 60 seconds by default) and automatically save your post while you work. Aside from the <a href="http://perishablepress.com/press/2008/03/17/wordpress-tip-careful-with-that-autosave-eugene/" title="WordPress Tip: Careful with that Autosave, Eugene">occasional hiccup</a>, AutoSave works great and is a genuine benefit to most WordPress users. Unlike version revisioning, AutoSave does not create a new database entry for every save. Instead, a single database entry is created for each post and is updated with each AutoSave cycle. AutoSave isn&rsquo;t perfect, however, and many folks find the time interval between saves either too brief or too long. Fortunately, WordPress makes it easy to modify the autosave interval with a simple <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/" title="WordPress Configuration Tricks">configuration trick</a>:</p>
<p><code>define('AUTOSAVE_INTERVAL', 300); // in seconds</code></p>
<p>Simply specify your desired autosave interval (in seconds) and add to your <code>wp-config.php</code> file to enjoy immediate results.</p>
<p>If you are one of the rare individuals who prefers to write <em>without</em> the autosave feature, here is an easy way to turn it off:</p>
<pre><code>function disable_autosave() {
	wp_deregister_script('autosave');
}
add_action('wp_print_scripts','disable_autosave');</code></pre>
<p>Just add that slice of code to your theme&rsquo;s <code>functions.php</code> and say goodbye to Autosave!</p>
<h3>WordPress Post Revisioning Feature</h3>
<p>WordPress implemented Post Revisioning (aka Version Revisioning) in version 2.6. Its function is to record changes made to your documents by storing unique revisions in the database. While this feature may benefit a few users, it is widely understood that most WordPress users have no need for this level of functionality. In my humble opinion, the revisioning &ldquo;feature&rdquo; is overkill and completely excessive. It should have been left out of the core (i.e., released as a plugin) or there should be an Admin option to completely disable it. Post revisioning creates extraneous database content and, in my experience, functions inconsistently and unpredictably. Fortunately, there is an easy way to disable it by adding the following line to your <code>wp-config.php</code> file:</p>
<p><code>define('WP_POST_REVISIONS',false);</code></p>
<p>Or, if you prefer to keep the versioning functionality but limit the number of allowed revisions, add the following line to your <code>wp-config.php</code> file:</p>
<p><code>define('WP_POST_REVISIONS',3);</code></p>
<p>There is even a way to clean up your database by deleting all post-revision data. <a href="http://andreineculau.com/blog/2008/07/delete-wordpress-26-revisions/" title="Delete WordPress 2.6 Revisions">Andrei Neculau</a> shows us how via this handy little <acronym title="Structured Query Language">SQL</acronym> command:</p>
<pre><code>DELETE a,b,c FROM wp_posts a 
LEFT JOIN wp_term_relationships b 
ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c 
ON (a.ID = c.post_id) WHERE a.post_type = 'revision';</code></pre>
<p>That magical query will nuke all post-revisions and associated meta-data from the database.</p>
<h3>AutoSave + Versioning = Chaos?</h3>
<p>So far, everything presented in this article is fairly straightforward. At this point, I would like to discuss a persistent post-reversioning issue that continues to rear its ugly head even when post revisioning is disabled via the previously prescribed method. Apparently, there is no way to disable WordPress&rsquo; post-revisioning functionality. It continues to work behind the scenes even after setting the <code>WP_POST_REVISIONS</code> variable to <code>false</code> in the configuration file.</p>
<p>Why do I say this? Because I have experienced the following series of events with several different WordPress installations:</p>
<ol>
<li>Install WordPress</li>
<li>Disable Post-Revisioning</li>
<li>Write a post, save it, edit it</li>
<li>Notice a message that says something like this:</li>
</ol>
<blockquote><p><em>There is an autosave of this page that is more recent than the version below.</em></p></blockquote>
<p>I can see how the timestamp on an autosave may conflict with the actual post during post editing, but when the database is examined after receiving this message, multiple post revisions are usually found. Apparently, WordPress is still saving post revisions behind the scenes even when revisioning has been disabled. With revisioning disabled, an option to compare reversions will never be shown explicitly, but the comparative functionality continues to operate. Further, there is no way to examine a list of the unintended post revisions. They exist in the database, but not in the Admin area. Thus, to see and compare these revisions, you need to do it manually. Here is a recipe for doing so:</p>
<ul>
<li>Log into a database interface like phpMyAdmin</li>
<li>Run the following <acronym title="Structured Query Language">SQL</acronym> query:</li>
</ul>
<pre><code>SELECT * FROM `wp_posts` WHERE post_type = "revision"</code></pre>
<p>If this query returns results, WordPress has been saving revisions without your consent. To delete these revisions and all of their post data, see the method prescribed above. To see and compare different revisions in the WordPress Admin before taking action, continue with the following steps (screenshot provided for clarity):</p>
<p><img src="http://digwp.com/wp-content/blog-images/wordpress-revisions.gif" alt="[ Screenshot: Post ID columns as seen via phpMyAdmin ]" /><br /><small>Post ID columns as seen via phpMyAdmin</small></p>
<ul>
<li>Determine the <strong>original post ID</strong> for each set of revisions</li>
<li>Determine the <strong>revision post ID</strong> of each individual revision</li>
<li>For each set of revisions that you would like to compare, enter the following URL in your browser&rsquo;s address bar:</li>
</ul>
<pre><code>http://domain.tld/wp-admin/revision.php?action=diff&amp;right=X&amp;left=Y</code></pre>
<p>Edit the domain to match your own, and then replace &ldquo;<code>X</code>&rdquo; and &ldquo;<code>Y</code>&rdquo; with the revision post IDs of any two revisions you would like to compare (order does not seem to matter).</p>
<p>Repeat these steps to compare as many revisions as is necessary. To view an individual revision, edit the following code with the ID of the desired revision and enter it into your browser&rsquo;s address bar:</p>
<pre><code>http://domain.tld/wp-admin/revision.php?revision=N</code></pre>
<p>Once you have evaluated your autosaved revisions, they may be safely deleted, either all at once via the <acronym title="Structured Query Language">SQL</acronym> query provided above, or else individually by simply clicking the delete button (the red &ldquo;x&rdquo; in phpMyAdmin) next to each revision in the <code>wp_posts</code> table.</p>
<h3>Share your experience</h3>
<p>I&rsquo;m curious to know what other WordPress users think of the post-revisioning and auto-save features. Do you use them, and if so, how are they beneficial? Have you ever experienced unexpected or unexplainable behavior while writing a post while using post-revisioning functionality? It would also be interesting to find out how many people think the post-revisioning feature should have been included in the WordPress core.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/07/mastering-wordpress-post-revisioning-and-auto-save-features/">Permalink</a> | <a href="http://digwp.com/2009/07/mastering-wordpress-post-revisioning-and-auto-save-features/#comments">14 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/07/mastering-wordpress-post-revisioning-and-auto-save-features/&title=Mastering WordPress Post-Revisioning and Auto-Save Features">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/editing/" rel="tag">editing</a>, <a href="http://digwp.com/tag/optimization/" rel="tag">optimization</a>, <a href="http://digwp.com/tag/performance/" rel="tag">performance</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/07/mastering-wordpress-post-revisioning-and-auto-save-features/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Optimize WordPress Performance with the wp-config.phpÂ File</title>
		<link>http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/</link>
		<comments>http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 07:16:58 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=245</guid>
		<description><![CDATA[As you may recall, there are a ton of configuration tricks available for the WordPress wp-config.php file. So many in fact, that I think many people may have missed some of the choice definitions aimed at optimizing WordPress performance. In this post, we&#8217;ll explore the best ways to improve your site&#8217;s performance with WordPress&#8217; wp-config.php [...]]]></description>
			<content:encoded><![CDATA[<p>As you may recall, there are a <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/" title="WordPress Configuration Tricks">ton of configuration tricks</a> available for the WordPress <code>wp-config.php</code> file. So many in fact, that I think many people may have missed some of the choice definitions aimed at <strong>optimizing WordPress performance</strong>. In this post, we&rsquo;ll explore the best ways to improve your site&rsquo;s performance with WordPress&rsquo; <code>wp-config.php</code> file.</p>
<p><span id="more-245"></span></p>
<h3>Hardcode your Blog Address and Site Address</h3>
<p>Every time your site references your Blog Address or Site Address via WordPress template tags, a query must be made to your database. <strong>Update:</strong> apparently, the database is only queried for these values for each page load, not for every use of a template tag (thanks to Nathan Rice for the <a href="#comment-577" title="Read original comment">clarification</a>). This happens more often than you may realize, as there are a number of template tags and parameters that access this information:</p>
<ul>
<li><code>&lt;?php get_bloginfo('url'); ?&gt;</code> &#8212; Returns the <acronym title="Uniform Resource Locator">URL</acronym> of your site</li>
<li><code>&lt;?php get_bloginfo('wpurl'); ?&gt;</code> &#8212; Returns the <acronym title="Uniform Resource Locator">URL</acronym> of your blog</li>
<li><code>&lt;?php bloginfo('url'); ?&gt;</code> &#8212; Displays the <acronym title="Uniform Resource Locator">URL</acronym> of your site</li>
<li><code>&lt;?php bloginfo('home'); ?&gt;</code> &#8212; Displays the <acronym title="Uniform Resource Locator">URL</acronym> of your blog</li>
</ul>
<p>These tags display or return the associated information about your blog based on the information supplied in the General Settings panel in the WordPress Admin (Settings &gt; General). Once entered in the Admin, your Blog Address and Site Address information is stored in the WordPress database and must be queried for every instance of each of the above template tags (and probably others as well). This may not seem like much, but the net effect on performance can be significant.</p>
<p>Fortunately, WordPress provides a way to eliminate these unnecessary database queries by enabling us to hardcode the values directly into the <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> construct. By defining the <code>WP_HOME</code> and <code>WP_SITEURL</code> constants in your site&rsquo;s <code>wp-config.php</code> file, you can boost performance by reducing the number of queries made to your WordPress database. The following two definitions were introduced in WordPress version 2.2 and override the database values without actually changing them (note that you should not include a trailing slash at the end of either URL):</p>
<pre><code>define('WP_HOME', 'http://digwp.com'); // blog url
define('WP_SITEURL', 'http://digwp.com'); // site url</code></pre>
<p>Note that these settings should match those specified in your WordPress Admin. Also, once these values are defined in the configuration file, they will be &ldquo;greyed out&rdquo; in the Admin General Settings panel. Removal of the definitions will restore your ability to edit them via the Admin panel.</p>
<h3>Hardcode your Template Path and Stylesheet Path</h3>
<p>In a similar vein, we may further optimize performance by eliminating database queries for your site&rsquo;s Template Path and Stylesheet Path. These two variables are defined based on the intrinsic structure of the WordPress installation as well as the name of the currently active theme. Many WordPress themes employ the following template tags to determine the values of these two variables:</p>
<ul>
<li><code>&lt;?php get_bloginfo('stylesheet_directory'); ?&gt;</code> &#8212; Returns the <acronym title="Uniform Resource Locator">URL</acronym> of the stylesheet directory of the active theme</li>
<li><code>&lt;?php get_bloginfo('template_directory'); ?&gt;</code> &#8212; Returns the <acronym title="Uniform Resource Locator">URL</acronym> of the active theme&rsquo;s directory</li>
<li><code>&lt;?php bloginfo('stylesheet_directory'); ?&gt;</code> &#8212; Displays the <acronym title="Uniform Resource Locator">URL</acronym> of the stylesheet directory of the active theme</li>
<li><code>&lt;?php bloginfo('template_directory'); ?&gt;</code> &#8212; Displays the <acronym title="Uniform Resource Locator">URL</acronym> of the active theme&rsquo;s directory</li>
<li><code>&lt;?php get_stylesheet_directory(); ?&gt;</code> &#8212; Returns the stylesheet directory path for the current theme</li>
<li><code>&lt;?php get_template_directory() ?&gt;</code> &#8212; Returns the absolute path for the template directory of the current theme</li>
</ul>
<p>These tags function by assuming a standard directory structure for the WordPress installation (i.e., <code>/wp-content/themes/</code>) and then query the database for the value of the current active theme. </p>
<p>As with the predefined constants for Blog Address and Site Address (see previous section), you can also boost performance by eliminating database queries for your site&rsquo;s Template Path and Stylesheet Path. The following two definitions were introduced in WordPress version 2.2 and override the database values without actually changing them (note that you should not include a trailing slash at the end of either URL):</p>
<pre><code>define('TEMPLATEPATH', '/absolute/path/to/wp-content/themes/H5');
define('STYLESHEETPATH', '/absolute/path/to/wp-content/themes/H5');</code></pre>
<p>Note that hardcoding these values will disable your ability to switch themes successfully via the WordPress Admin (Appearance &gt; Themes). To do so, simply remove these two definitions, make the switch, and then edit them with the name of the new theme. </p>
<h3>Define your four Salt Values</h3>
<p>In my article, <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/" title="WordPress Configuration Tricks">WordPress Configuration Tricks</a>, I discuss the four security keys that were introduced in WordPress version 2.7. These four keys work silently in the background and protect your site by enhancing cookie encryption. The values for these four keys should be as random and complicated as possible, and are easily and automatically generated at the <a href="http://api.wordpress.org/secret-key/1.1/" title="WordPress.org secret-key service">WordPress.org secret-key service</a>. These predefined keys are placed into your <code>wp-config.php</code> file and may be changed at any time (thereby nullifying your visitors&rsquo; old cookies):</p>
<pre><code>define('AUTH_KEY',        '#Sl2}YZFq~~.g=3HT 4+_;l7;#N~e]5._J!u*Y=qvFNhi(E{B9p% }+&gt;rnh8t~Bl');
define('SECURE_AUTH_KEY', 'G/Huwa6Ri6zkkEqz (~*J$O8M72pe&gt;+YrdW|+N_s2*qD%rM,;jF1%c3M!vQ&gt;2`{i');
define('LOGGED_IN_KEY',   'r/N1ssKv7Vxnd2Oj!O3oP+/-[}eSboXBt=(%T`.N7aA%}I%|-):[&amp;@D`r&gt;:Rk_R#');
define('NONCE_KEY',       '~1 -@]b]LMEPzbv#)d1Cz(.7_KHVyP@UG[J&amp;31_r5aC0WAWxpvGF;a^-@YnWt7x@');</code></pre>
<p>Used in conjunction with these four definitions are four corresponding &ldquo;salt&rdquo; values. Ideally, these four salt values are as complex and random as the their four encryption-key counterparts. If the salt is not defined elsewhere, WordPress will query the database to generate their values. These generated values are then stored in the WordPress database and must be queried for every use of the encryption keys. Obviously, eliminating these database queries will serve us well in boosting the performance of our WordPress-powered sites. Thanks to the <a href="#comment-400" title="Read original comment">heads up</a> from <a href="http://blog.avirtualhome.com/">Peter van der Does</a>, we now know that these four salt constants also may be defined in the <code>wp-config.php</code> file. Here is an example:</p>
<pre><code>define('AUTH_SALT',        '&gt;#m3m?hTy0Lg&lt;oB=ko7Z`8Z&amp;(1gs=FhPug^NniIVpkdo+&amp; c+$]B),H9*7ZMfDGT');
define('SECURE_AUTH_SALT', 'f~N&gt;{|CYc5uuED{^f7)+hEbnh(E,&lt;* 3:7DFcc$)SJS|=Tw^};@ti$714f:-zxjC');
define('LOGGED_IN_SALT',   ':-HRrr}&lt;zW=QwH8F!aUa#|q-xe(pjFK$wt!8G69ttHp4hNfxs[+u-mdxF=3ll{5e');
define('NONCE_SALT',       'F)H4}[Xh?F={lMW8F|gVH~iI!8$0*?X!7IZfr`0Q2-P1EL?:E[0hE&gt;&gt;(+!tTZ/H$');</code></pre>
<p>Exactly how do these salt values interact with their corresponding security keys? As Peter explains in his comment:</p>
<blockquote><p><em>The <code>NONCE_KEY</code>, for example is used by the functions <code>wp_nonce_field</code> and <code>check_admin_referer</code>. The strings passed on by these functions are used to create a unique hash. The function used is to create this hash is <code>hash_hmac</code> and the key for this function is the <code>NONCE_KEY</code> + <code>NONCE_SALT</code>.</em></p></blockquote>
<p>The bottom line here is that, by including these four salt definitions alongside your four security keys, you can improve site performance by eliminating extraneous database queries. You can even use the same <a href="http://api.wordpress.org/secret-key/1.1/" title="WordPress.org secret-key service">secret-key service</a> to generate the random data (just remember to only copy the salt values and not the entire block of code). And, as with the security-key definitions, the salt values may be changed at any time.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/">Permalink</a> | <a href="http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/#comments">31 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/&title=Optimize WordPress Performance with the wp-config.phpÂ File">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/config/" rel="tag">config</a>, <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/optimization/" rel="tag">optimization</a>, <a href="http://digwp.com/tag/performance/" rel="tag">performance</a>, <a href="http://digwp.com/tag/security/" rel="tag">Security</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>WordPress Configuration Tricks</title>
		<link>http://digwp.com/2009/06/wordpress-configuration-tricks/</link>
		<comments>http://digwp.com/2009/06/wordpress-configuration-tricks/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 14:53:51 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=196</guid>
		<description><![CDATA[Many WordPress users know the wp-config.php file as the key to the WordPress database. It is where you set the database name, username, password, and location. You know the one: The wp-config.php file contains the information required for WordPress to connect to the database But what many users don&#8217;t know is that the wp-config.php file [...]]]></description>
			<content:encoded><![CDATA[<p>Many WordPress users know the <code>wp-config.php</code> file as the <strong>key to the WordPress database</strong>. It is where you set the database name, username, password, and location. You know the one:</p>
<p><img src="http://digwp.com/wp-content/blog-images/wp-config-screens.gif" alt="[ The WordPress Configuration File ]" title="File-list view and file-content view for the wp-config.php file" /><br /><small>The wp-config.php file contains the information required for WordPress to connect to the database</small></p>
<p>But what many users don&rsquo;t know is that the <code>wp-config.php</code> file may be used to specify a wide variety of configurational settings, enabling you to improve the functionality, performance, and security of your WordPress-powered site. In this article, I share as many of these configurational tricks as I have been able to collect over the years. This guide covers everything in the <a href="http://codex.wordpress.org/Editing_wp-config.php" title="WordPress Codex: Editing the wp-config.php file">WordPress Codex</a>, as well some additional tricks that you probably haven&rsquo;t seen before. If you know of any other WordPress configuration tricks, share them in the comments and I will add them to the post.</p>
<p><span id="more-196"></span></p>
<h3>Database Credentials *</h3>
<p>This set of four configurational definitions are required for WordPress to connect to the database:</p>
<pre><code>define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');</code></pre>
<p>Database name, username, and password should be readily available to you during database creation, but the <code>DB_HOST</code> value may be more difficult to acquire. Most commonly, this value is simply &ldquo;<code>localhost</code>&rdquo;, but if that doesn&rsquo;t work, here are a few other values to try:</p>
<ul>
<li><strong>1and1 Hosting</strong> &#8212; <code>db12345678</code></li>
<li><strong>DreamHost</strong> &#8212; <code>mysql.example.com</code></li>
<li><strong>GoDaddy</strong> &#8212; <code>h41mysql52.secureserver.net</code></li>
<li><strong>ICDSoft</strong> &#8212; <code>localhost:/tmp/mysql5.sock</code></li>
<li><strong>MediaTemple (GS)</strong> &#8212; <code>internal-db.s44441.gridserver.com</code></li>
<li><strong>Pair Networks</strong> &#8212; <code>dbnnnx.pair.com</code></li>
<li><strong>Yahoo</strong> &#8212; <code>mysql</code></li>
</ul>
<p>You can even specify an alternate port for your database server. Here are two examples:</p>
<p><code>define('DB_HOST', 'localhost:1234');</code><br />
<code>define('DB_HOST', 'mysql.domain.tld:1234');</code></p>
<p>Another cool trick is to detect the database server value automatically:</p>
<p><code>define('DB_HOST', $_ENV{DATABASE_SERVER});</code></p>
<p>If all of these fail, or if you are still having problems, consult your hosting provider for assistance.</p>
<h3>Database Character Set and Collation *</h3>
<p>As of WordPress version 2.2, you may specify a character set for your MySQL database tables. Generally, there is no reason to change the default character-set value of UTF-8, which is usually perfect because it supports all languages. Note that you should only use this definition if it already exists in your <code>wp-config.php</code> file. Here is the default (and recommended) setting:</p>
<pre><code>define('DB_CHARSET', 'utf8');</code></pre>
<p>WordPress version 2.2 also enables you to specify the collation, which is the sort order of your database character set. Setting the collation is generally handled automatically by MySQL according to the character set, which is enabled by leaving the collation value blank as done in the default setting for this definition. Note that you should only use this definition if it already exists in your <code>wp-config.php</code> file. Here is the default (and recommended) setting:</p>
<pre><code>define('DB_COLLATE', '');</code></pre>
<h3>Security Keys *</h3>
<p>As of WordPress 2.7, there are four security keys available that are designed to insure better cookie encryption. These keys work silently in the background and should be as random and complicated as possible (no, you will never need to remember them). The easiest way to generate these keys is to do it automatically at the <a href="http://api.wordpress.org/secret-key/1.1/" title="WordPress.org secret-key service">WordPress.org secret-key service</a>. Simply visit that link and copy/paste the results into your <code>wp-config.php</code> file. Note that these keys may be changed anytime, and doing so will invalidate all of your users&rsquo; existing cookies so that they will have to re-login to your site.</p>
<pre><code>define('AUTH_KEY', ':dr+%/5V4sAUG-gg%aS*v;&amp;xGhd%{YV)p:Qi?jXLq,&lt;h\\`39');
define('SECURE_AUTH_KEY', '@*+S=8\"\'+\"}]&lt;m#+}V)p:Qi?jXLq,&lt;h\\`39m_(');
define('LOGGED_IN_KEY', 'S~AACm4h1;T^\"qW3_8Zv!Ji=y|)~5i63JI |Al[(&lt;YS');
define('NONCE_KEY', 'k1+EOc-&amp;w?hG8j84&gt;6L9v\"6C89NH?ui{*3\\(t09mumL/fF');</code></pre>
<h3>Database Prefix *</h3>
<p>The database prefix setting is particularly useful for increasing the security of your site and for housing multiple WordPress installations in a single database. By changing the default value of &ldquo;<code>wp_</code>&rdquo; to something randomly unique, you mitigate commonly targeted attack vectors and improve the overall security of your site. Here is the default setting:</p>
<pre><code>$table_prefix  = 'wp_';</code></pre>
<p>There are tons of crackers out there probing sites for this default database prefix. Changing it to something like &ldquo;x777_&rdquo; is a good way to avoid these types of targeted attacks. </p>
<p>You can also use this setting to install multiple instances of WordPress using the same database. Simply specify a unique database prefix for each installation:</p>
<pre><code>$table_prefix  = 'wp1_'; // first blog
$table_prefix  = 'wp2_'; // second blog
$table_prefix  = 'wp3_'; // third blog</code></pre>
<h3>Language Settings *</h3>
<p>WordPress makes it possible to specify a language-translation file and its associated directory. The language translation file is assumed to be of the &ldquo;<code>.mo</code>&rdquo; variety, and its default location (if no explicit path is specified) is assumed to be <code>wp-content/languages</code> (first) and then <code>wp-includes/languages</code> (second). Here is the default setting:</p>
<pre><code>define('WPLANG', '');
define('LANGDIR', '');</code></pre>
<h3>Directory Settings *</h3>
<p>Technically not something that you should need to mess with, the default <code>wp-config.php</code> file contains a few lines that specify the absolute path and include the settings file. I include them here for the sake of completeness:</p>
<pre><code>/** WordPress absolute path to the Wordpress directory. */
if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');</code></pre>
<h3>Blog Address and Site Address</h3>
<p>Now we&rsquo;re getting to some of the cool stuff. By default, these two configurational definitions are not included in the <code>wp-config.php</code> file, but they should be added to improve performance. These two settings were introduced in WordPress version 2.2 and override the database value without actually changing them. Adding these two definitions in your site&rsquo;s <code>wp-config.php</code> file reduces the number of database queries and thus improves site performance. These settings should match those specified in your WordPress Admin. Here is an example (note that you should not include a trailing slash at the end of either URL):</p>
<pre><code>define('WP_HOME', 'http://digwp.com');
define('WP_SITEURL', 'http://digwp.com');</code></pre>
<p>A cool trick is to set these values dynamically by using the global server variable:</p>
<p><code>define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST'].'/path/to/wordpress');</code><br />
<code>define('WP_SITEURL', 'http://'.$_SERVER['HTTP_HOST'].'/path/to/wordpress');</code></p>
<h3>Template Path and Stylesheet Path</h3>
<p>As with the predefined constants for blog address and site address (see previous section), you can also boost performance by eliminating database queries for the template path and stylesheet path for your site. Here are the default values for these two definitions:</p>
<pre><code>define('TEMPLATEPATH', get_template_directory());
define('STYLESHEETPATH', get_stylesheet_directory());</code></pre>
<p>As is, these two definitions are still querying the database, but we can eliminate these extraneous queries by hardcoding the values into place:</p>
<pre><code>define('TEMPLATEPATH', '/absolute/path/to/wp-content/themes/active-theme');
define('STYLESHEETPATH', '/absolute/path/to/wp-content/themes/active-theme');</code></pre>
<h3>Disable Cache and Cache Expiration</h3>
<p>These two options apply to older versions of WordPress that are still using the default object-based caching mechanism. The first definition enables you to enable or disable the cache, while the second definition enables you to specify the cache expiration time.</p>
<p><strong>Enable the cache</strong></p>
<pre><code>define('WP_CACHE', true);      // enable the cache
define('ENABLE_CACHE', true);  // enable the cache
define('CACHE_EXPIRATION_TIME', 3600); // in seconds</code></pre>
<p><strong>Disable the cache</strong></p>
<pre><code>define('WP_CACHE', false);     // disable the cache
define('DISABLE_CACHE', true); // disable the cache</code></pre>
<h3>Specify Cookie Domain</h3>
<p>There are several reasons why you want to specify a cookie domain for your site. A common example involves preventing cookies from being sent with requests for static content on subdomains. In this case, you would use this definition to tell WordPress to send cookies only to your non-static domain. This could be a significant performance boost. Here are some examples of setting various cookie path and cookie domain information:</p>
<pre><code>define('COOKIE_DOMAIN', '.digwp.com'); // don't omit the leading '.'
define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home').'/'));
define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl').'/'));
define('PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL));
define('ADMIN_COOKIE_PATH', SITECOOKIEPATH.'wp-admin');</code></pre>
<h3>Override File Permissions</h3>
<p>If your web host&rsquo;s default file permissions are too restrictive, adding these definitions to your WordPress configuration file may help resolve the issue. Note that you don&rsquo;t need the quotes around the permission values. Here is an example:</p>
<pre><code>define('FS_CHMOD_FILE', 0755);
define('FS_CHMOD_DIR', 0755);</code></pre>
<h3>View All Defined Constants</h3>
<p>Need to view all predefined constants? Good news, this PHP function will return an array of all currently defined constants:</p>
<pre><code>print_r(@get_defined_constants());</code></pre>
<h3>Custom User and Usermeta Tables</h3>
<p>What about custom user and usermeta tables? Yep, you can do that too, with the following definitions:</p>
<pre><code>define('CUSTOM_USER_TABLE', $table_prefix.'my_users');
define('CUSTOM_USER_META_TABLE', $table_prefix.'my_usermeta');</code></pre>
<h3>FTP/SSH Constants</h3>
<p>This set of configurational definitions is designed to help users locate and utilize FTP/SSH connections. Here is a example set of predefined constants for FTP/SSH updates:</p>
<pre><code>define('FS_METHOD', 'ftpext'); // forces the filesystem method: "direct", "ssh", "ftpext", or "ftpsockets"
define('FTP_BASE', '/path/to/wordpress/'); // absolute path to root installation directory
define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/'); // absolute path to "wp-content" directory
define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/'); // absolute path to "wp-plugins" directory
define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub'); // absolute path to your SSH public key
define('FTP_PRIVKEY', '/home/username/.ssh/id_rsa'); // absolute path to your SSH private key
define('FTP_USER', 'username'); // either your FTP or SSH username
define('FTP_PASS', 'password'); // password for FTP_USER username
define('FTP_HOST', 'ftp.domain.tld:21'); // hostname:port combo for your SSH/FTP server</code></pre>
<h3>Moving Your wp-content directory</h3>
<p>As of WordPress version 2.6, you may change the default location of the <code>wp-content</code> directory. There are several good reasons for doing this, including enhancement of site security and facilitation of FTP updates. Here are some examples:</p>
<pre><code>// full local path of current directory (no trailing slash)
define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'].'/path/wp-content'); 

// full URI of current directory (no trailing slash)
define('WP_CONTENT_URL', 'http://domain.tld/path/wp-content');</code></pre>
<p>You may also further specify a custom path for your <code>plugins</code> directory. This may help with compatibility issues with certain plugins:</p>
<pre><code>// full local path of current directory (no trailing slash)
define('WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'].'/path/wp-content/plugins'); 

// full URI of current directory (no trailing slash)
define('WP_PLUGIN_URL', 'http://domain.tld/path/wp-content/plugins');</code></pre>
<h3>Dealing with Post Revisions</h3>
<p>Recent versions of WordPress provides a post-revisioning system that enables users to save different versions of their blog posts and even revert to previously saved versions if necessary. Regardless of how much you do or do not despise this amazingly awesome feature, here are a couple of configurational definitions that may prove useful for you&nbsp;;)</p>
<p><strong>Limit the number of saved revisions</strong></p>
<pre><code>define('WP_POST_REVISIONS', 3); // any integer, but don't get too crazy</code></pre>
<p><strong>Disable the post-revisioning feature</strong></p>
<pre><code>define('WP_POST_REVISIONS', false);</code></pre>
<h3>Specify the Autosave Interval</h3>
<p>In a similar vein as the post-revisioning feature is WordPress&rsquo; actually useful Autosave functionality. By default, WordPress saves your work every 60 seconds, but you can totally modify this setting to whatever you want. Don&rsquo;t get too crazy though, unless you want to stress-out your server&nbsp;;)</p>
<pre><code>define('AUTOSAVE_INTERVAL', 160); // in seconds</code></pre>
<h3>Debugging WordPress</h3>
<p>Since WordPress version 2.3.1, users have been able to display certain errors and warnings to help with the debugging of their site. As of WordPress version 2.5, enabling error reporting raises the reporting level to <code>E_ALL</code> and activates warnings for deprecated functions. By default (i.e., if no definition is specified in the <code>wp-config.php</code> file), error reporting is disabled.</p>
<pre><code>define('WP_DEBUG', true); // enable debugging mode
define('WP_DEBUG', false); // disable debugging mode (default)</code></pre>
<h3>Error Log Configuration</h3>
<p>Here is an easy way to enable basic error logging for your WordPress-powered site. Create a file called &ldquo;<code>php_error.log</code>&rdquo;, make it server-writable, and place it in the directory of your choice. Then edit the path in the third line of the following code and place into your <code>wp-config.php</code> file:</p>
<pre><code>@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/home/path/domain/logs/php_error.log');</code></pre>
<h3>Increase PHP Memory</h3>
<p>If you are receiving error messages telling you that your &ldquo;Allowed memory size of xxx bytes exhausted,&rdquo; this setting may help resolve the issue. AS of WordPress version 2.5, the <code>WP_MEMORY_LIMIT</code> definition enables you to specify the maximum amount of memory that may be used by PHP. By default, WordPress will automatically attempt to increase PHP memory up to 32MB, so this setting is only needed for values higher than 32MB. Note that some web hosts disable your ability to increase PHP memory, so you may need to beg for them to do it. Here are some examples:</p>
<pre><code>define('WP_MEMORY_LIMIT', '64M');
define('WP_MEMORY_LIMIT', '96M');
define('WP_MEMORY_LIMIT', '128M');</code></pre>
<h3>Save and Display Database Queries for Analysis</h3>
<p>This technique is perfect for saving database queries and displaying the information for subsequent analysis. The process saves each query, its associated function, and its total execution time. This information is saved as an array and may be displayed on any theme template page. To do this, first add the following directive to your <code>wp-config.php</code> file:</p>
<pre><code>define('SAVEQUERIES', true);</code></pre>
<p>Then, in the footer of your active theme, place the following code:</p>
<pre><code>// display the query array for admin only
if (current_user_can('level_10')) {
	global $wpdb;
	echo "&lt;pre&gt;";
	print_r($wpdb-&gt;queries);
	echo "&lt;/pre&gt;";
}</code></pre>
<p>Here is a single-line version of this function:</p>
<pre><code>&lt;?php if (current_user_can('level_10')) { global $wpdb; echo "&lt;pre&gt;"; print_r($wpdb-&gt;queries); echo "&lt;/pre&gt;"; } ?&gt;</code></pre>
<h3>Control Proxy Access</h3>
<p>Since WordPress 2.8, the configuration file may be used to define constants involved with blocking, allowing and filtering access to specific hosts from behind a proxy server. For example, if you host your WordPress site on an intranet network, you may prevent access to all external hosts and only allow requests from localhost and your blog using the first definition below. You may also allow specific hosts access with a comma-separated list of allowed hostnames, as demonstrated in the third definition below. Note that you should allow <code>api.wordpress.org</code> access to ensure proper functionality of core files and plugins.</p>
<pre><code>define('WP_HTTP_BLOCK_EXTERNAL', true);  // block external requests
define('WP_HTTP_BLOCK_EXTERNAL', false); // allow external requests
define('WP_ACCESSIBLE_HOSTS', 'api.wordpress.org'); // whitelist hosts</code></pre>
<p>Whew! I&rsquo;m wiped. Time for a little break&nbsp;:)</p>
<p>* <small>Included in the default wp-config.php file (as of WordPress version 2.8)</small></p>
<h4>Translations of this article</h4>
<p><a href="http://www.desenvolvimentoparaweb.com/wordpress/truques-de-configuracao-do-wordpress/">WordPress Configuration Tricks in Brazilian Portuguese</a> by TÃ¡rcioZemel</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/">Permalink</a> | <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/#comments">94 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/06/wordpress-configuration-tricks/&title=WordPress Configuration Tricks">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/config/" rel="tag">config</a>, <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/optimization/" rel="tag">optimization</a>, <a href="http://digwp.com/tag/security/" rel="tag">Security</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/06/wordpress-configuration-tricks/feed/</wfw:commentRss>
		<slash:comments>94</slash:comments>
		</item>
	</channel>
</rss>

