<?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; Theme</title>
	<atom:link href="http://digwp.com/tag/theme/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Fri, 18 May 2012 18:21:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Displaying Theme Data with WordPress</title>
		<link>http://digwp.com/2011/12/displaying-theme-data-with-wordpress/</link>
		<comments>http://digwp.com/2011/12/displaying-theme-data-with-wordpress/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 18:36:29 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=5457</guid>
		<description><![CDATA[A cool trick you can do with WordPress is display information directly from your theme&#8217;s style.css stylesheet. I recently used this on a site where the theme&#8217;s version number is used throughout the template to keep things current and consistent. get_theme_data() The function that makes it possible is called get_theme_data(), and it simply returns an [...]]]></description>
			<content:encoded><![CDATA[<p>A cool trick you can do with WordPress is display information directly from your theme&#8217;s <code>style.css</code> stylesheet. I recently used this on a site where the theme&#8217;s version number is used throughout the template to keep things current and consistent.</p>
<p><span id="more-5457"></span></p>
<h3>get_theme_data()</h3>
<p>The function that makes it possible is called <a href="http://codex.wordpress.org/Function_Reference/get_theme_data">get_theme_data()</a>, and it simply returns an array of information about any of your theme files. Here is how it&#8217;s used in your theme template:</p>
<pre><code>&lt;?php get_theme_data( $theme_filename ); ?&gt;</code></pre>
<p>So <code>$theme_filename</code> is required and should be the path and filename of your theme&#8217;s <code>style.css</code> file. There is no default value for this, so you need to ensure a proper value.</p>
<p>So what information can you display with <code>get_theme_data()</code>? The function returns an array of values that basically comprises the different meta items in your stylesheet. Here is a list of possible return values (all strings):</p>
<ul>
<li><code>Name</code> &ndash; theme name</li>
<li><code>Title</code> &ndash; either theme name or linked theme name</li>
<li><code>URI</code> &ndash; theme <abbr title="Uniform Resource Identifier">URI</abbr></li>
<li><code>Description</code> &ndash; wptexturized version of the theme name</li>
<li><code>AuthorURI</code> &ndash; theme author URI</li>
<li><code>Template</code> &ndash; theme parent template, if exists</li>
<li><code>Version</code> &ndash; theme version number</li>
<li><code>Status</code> &ndash; theme status (default: <code>publish</code>)</li>
<li><code>Tags</code> &ndash; theme tags</li>
<li><code>Author</code> &ndash; author name or linked author name</li>
</ul>
<p>Note that these return values are <strong>case-sensitive</strong> and will not work if the first letter is not capitalized.</p>
<h3>Examples</h3>
<p>The Codex provides this example for getting and displaying the theme <code>Name</code> and <code>Author</code>:</p>
<pre><code>&lt;?php

    /*
     * Assign theme folder name that you want to get information.
     * make sure theme exist in wp-content/themes/ folder.
     */

    $theme_name = 'twentyeleven'; 

   /*
    * Do not use get_stylesheet_uri() as $theme_filename,
    * it will result in PHP fopen error if allow_url_fopen is set to Off in php.ini,
    * which is what most shared hosting does. You can use get_stylesheet_directory()
    * or get_template_directory() though, because they return local paths.
    */

    $theme_data = get_theme_data( get_theme_root() . '/' . $theme_name . '/style.css' );
    echo $theme_data['Title'];
    echo $theme_data['Author'];

?&gt;</code></pre>
<p>This should get you going.. just copy/paste into your theme template and indicate the theme name in that first line of code. Displaying other bits of theme data is matter of editing/replicating those last two lines. </p>
<p>Once you see how it works, you can do cool stuff with it, like display your theme&#8217;s version number sort of globally throughout your site. I&#8217;m using this technique to append version parameters to my stylesheet <abbr title="Uniform Resource Locator">URL</abbr>s, like so:</p>
<pre><code>&lt;link rel="stylesheet" href="&lt;?php bloginfo('stylesheet_directory'); ?&gt;/style.css&lt;?php if(function_exists('theme_version')) theme_version(); ?&gt;"&gt;</code></pre>
<p>..and the output markup looks like this (notice the appended version parameter, <code>?v=1.3</code>):</p>
<pre><code>&lt;link rel="stylesheet" href="http://example.com/wp-content/themes/xycss/style.css?v=1.3"&gt;</code></pre>
<p>Because I am using multiple stylesheets, this method really saves a LOT of time trying to keep track of everything. Here is the <code>theme_version()</code> function that goes in your theme&#8217;s <code>functions.php</code> file:</p>
<pre><code>// display version number
function theme_version() {
    $theme_name = 'xycss'; // customize with your theme name
    $theme_data = get_theme_data( get_theme_root() . '/' . $theme_name . '/style.css' );
    echo '?v=' . $theme_data['Version'];
}</code></pre>
<p>And with a few modifications, you can also display your theme&#8217;s information in your posts and pages via <strong>shortcode</strong>:</p>
<pre><code>// version number shortcode
function theme_version_shortcode() {
    $theme_name = 'xycss'; // customize with your theme name
    $theme_data = get_theme_data( get_theme_root() . '/' . $theme_name . '/style.css' );
    return $theme_data['Version'];
}
add_shortcode('theme_version', 'theme_version_shortcode');</code></pre>
<p>With that second snippet in your <code>functions.php</code> file, displaying your theme info directly in pages is as easy as writing this:</p>
<p><code>[theme_version]</code></p>
<p>..and the output:</p>
<p><code>1.3</code></p>
<p>It&#8217;s pretty cool stuff, and I&#8217;m sure there&#8217;s tons more you can do with it too. If you know any tricks or tips, please share in the comments, Thanks :)</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/12/displaying-theme-data-with-wordpress/">Permalink</a> | <a href="http://digwp.com/2011/12/displaying-theme-data-with-wordpress/#comments">10 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/12/displaying-theme-data-with-wordpress/&title=Displaying Theme Data with WordPress">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/12/displaying-theme-data-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Tumblr Links with Post Formats</title>
		<link>http://digwp.com/2011/04/tumblr-links-post-formats/</link>
		<comments>http://digwp.com/2011/04/tumblr-links-post-formats/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 17:49:20 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[post-formats]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3865</guid>
		<description><![CDATA[With WordPress 3.1&#8217;s new Post Format functionality, it&#8217;s easier than ever to create your own Tumblr-style Link posts. We do this right here at DigWP.com using our own hand-rolled method. Scroll through a page or two of the site&#8217;s most recent posts, and you&#8217;ll see that Link posts are formatted and styled differently than regular [...]]]></description>
			<content:encoded><![CDATA[<p>With WordPress 3.1&rsquo;s new <strong>Post Format</strong> functionality, it&rsquo;s easier than ever to create your own <strong>Tumblr-style Link posts</strong>. We do this right here at <a href="http://digwp.com/">DigWP.com</a> using our own <a href="http://digwp.com/2009/09/tumblr-style-links-for-posts-and-feeds/" title="How to Implement Tumblr-Style Links for Posts and Feeds">hand-rolled method</a>. Scroll through a page or two of the site&rsquo;s most recent posts, and you&rsquo;ll see that <strong>Link posts</strong> are formatted and styled differently than regular posts (see screenshot below). In this tutorial, you&#8217;ll learn how to use <strong>WordPress&#8217; new Post Formats</strong> to setup your own <strong>Tumblr-style Links</strong> in <em>3 easy steps</em>.</p>
<p><span id="more-3865"></span></p>
<p><img src="http://digwp.com/wp-content/blog-images/post-formats-digwp-links.gif" alt="[ Screenshot: Link Posts at DigWP.com ]" /></p>
<p>Link posts are meant for quick links to <em>external</em> resources. Ideally, they&#8217;re styled for easy recognition without breaking the flow of post content. Link posts look like link posts, Asides look like asides, Galleries look like galleries, and so on. Here&#8217;s a chart showing the differences between <em>regular posts</em> and <em>Link posts</em>:</p>
<p><img src="http://digwp.com/wp-content/blog-images/post-formats-compare.gif" alt="[ Regular vs Link Posts ]" /></p>
<p>Notice the <strong>key difference</strong> between the two types of posts: <strong>regular post titles</strong> link to the <em>single-view</em> of the post, but <strong>Link post titles</strong> link to the <abbr title="Uniform Resource Locator">URL</abbr> of an <em>external resource</em> (i.e., whatever awesome thing you&#8217;re sharing with your visitors). This makes it super-easy to share links via <em>true</em> &#8220;Tumblr-style&#8221; Link posts. And with WordPress 3.1&rsquo;s new <strong>Post Formats</strong> functionality, it&#8217;s <em>easier than ever</em> to do.</p>
<h3>Easy, 3-Step Tutorial</h3>
<p>Here&#8217;s an overview of the tutorial:</p>
<ol>
<li><a href="#step1">Enable Post Formats via <code>functions.php</code></a></li>
<li><a href="#step2">Include the conditional template tags in your theme files</a></li>
<li><a href="#step3">Style with some <abbr title="Cascading Style Sheets">CSS</abbr> via <code>style.css</code> (optional)</a></li>
<li><a href="#usage">Usage and notes</a></li>
</ol>
<p>Even if you don&#8217;t implement this technique, the tutorial provides a great example of how Post Formats can be used to add variety and depth to any WordPress-powered site.</p>
<h3 id="step1">Step 1: Enable Post Formats</h3>
<p>First, make sure you have the latest version of WordPress (3.1 or better), and then <strong>enable Post Formats</strong> by adding this snippet to your theme&#8217;s <code>functions.php</code> file:</p>
<pre><code>// Enable Post Formats for WP 3.1+
add_theme_support('post-formats',array('aside','chat','gallery','image','link','quote','status','video','audio'));</code></pre>
<p>With that in place, all nine (+1 default) Post Formats will be enabled on your site. Next time you write or edit a post, you should see a <strong>Post Formats</strong> panel with options for each of these different formats. If you know you won&#8217;t be needing some of them, feel free to edit the parameter list in the code snippet. Otherwise, it&#8217;s totally fine to leave them all enabled &ndash; it doesn&#8217;t hurt anything &ndash; it&#8217;s just a matter of preference.</p>
<h3 id="step2">Step 2: Customize your theme files</h3>
<p>Next, in your theme&#8217;s template file(s), replace the markup/tags used to generate your post titles (located in the loop) with the following conditional code: </p>
<pre><code>&lt;?php if (has_post_format('link') &amp;&amp; get_post_meta($post-&gt;ID, 'LinkFormatURL', true)) : ?&gt;
			
	&lt;h2&gt;&lt;a href="&lt;?php echo get_post_meta($post-&gt;ID, 'LinkFormatURL', true); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
			
&lt;?php else : ?&gt;
			
	&lt;h2&gt;&lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
			
&lt;?php endif; ?&gt;</code></pre>
<p>The first line tests each post using <code>has_post_format</code> and <code>get_post_meta</code>. IF the post is a <strong>Link post</strong> (has &#8220;<code>link</code>&#8221; post format) AND has an alternate URL (via &#8220;<code>LinkFormatURL</code>&#8221; custom field), the post title will be Tumblr-style <em>as specified</em> in the second line of code. If <em>both</em> of those conditions <em>fail</em>, the post title will be the regular/default, as specified in the fourth line of code. You may use any <abbr title="PHP: Hypertext Preprocessor">PHP</abbr>/markup needed to customize your Link posts to suit your design.</p>
<p><strong id="step2update">Update:</strong> <a href="http://digwp.com/2011/04/tumblr-links-post-formats/#comment-20779" title="Read comment">Matt Wiebe</a> makes this step even easier. Instead of messing with your theme files, just add this snippet to your theme&#8217;s <code>functions.php</code>:</p>
<pre><code>// filter post title for tumblr links
function sd_link_filter($link, $post) {
     if (has_post_format('link', $post) &amp;&amp; get_post_meta($post-&gt;ID, 'LinkFormatURL', true)) {
          $link = get_post_meta($post-&gt;ID, 'LinkFormatURL', true);
     }
     return $link;
}
add_filter('post_link', 'sd_link_filter', 10, 2);</code></pre>
<p>This script filters the <code>post_link</code> and returns the correct URL based on the same conditions as before. Just plug-n-play &ndash; no other theme modifications required. Thanks to <a href="http://somadesign.ca/">Matt Wiebe</a> for sharing this more elegant method.</p>
<h3 id="step3">Step 3: Style with CSS</h3>
<p>Lastly and optionally, you are encouraged to customize the appearance of your custom Post Formats. Referring back to the opening screenshot, notice how Link posts stand out as distinct and easy to recognize as such. To style your Link posts with CSS, make sure your theme includes the <code>post_class()</code> tag in the outer <code>&lt;div&gt;</code> (or whatever) for each post. The <code>post_class()</code> function will then output the Post-Format name as a class attribute for each post. This provides a nice hook for hanging your custom CSS. Here is a simple example using our code from Step 2:</p>
<pre><code>.format-standard { width: 100%; }
.format-link     { width: 75%; }

.format-standard h2 { font-size: 24px; }
.format-link h2     { font-size: 16px; }

.format-standard a { color: #000; }
.format-link a     { color: #777; }</code></pre>
<p>Using the <code>.format-{whatever}</code> class attribute, it&#8217;s easy to style each of your Post Formats with a distinct appearance that&#8217;s easy to recognize.</p>
<h3 id="usage">Usage and Notes</h3>
<p>Once you get everything setup, posting Links is as easy as 1-2-3..</p>
<ol>
<li><strong>Write</strong> your Link post</li>
<li><strong>Choose</strong> the &#8220;Link&#8221; format type from the Format radio-button menu (located under the Publish panel)</li>
<li><strong>Add</strong> the Link URL (external resource) to a custom field named &#8220;<code>LinkFormatURL</code>&#8221; (see screenshot below)</li>
</ol>
<p><img src="http://digwp.com/wp-content/blog-images/post-formats-custom-field.gif" alt="[ Screenshot: Link Post Custom Field ]" /></p>
<p>And that&#8217;s all there is to it! After posting a new Link, it will be displayed using the format and styles that you&#8217;ve applied. A few notes:</p>
<ol>
<li>CSS hooks for post-formats are available via <code>post_class()</code></li>
<li>When customizing your theme as per Step 2, don&#8217;t forget about <code>archive.php</code>, <code>category.php</code>, and any other template files that use the loop</li>
<li>This tutorial sets up Tumblr-style Links for your blog only, but you can <a href="http://digwp.com/2009/09/tumblr-style-links-for-posts-and-feeds/" title="How to Implement Tumblr-Style Links for Posts and Feeds">check this post</a> to setup the Tumblr Links for feeds as well</li>
</ol>
<p>If you have any questions about setting this up on your site, leave a comment and we&#8217;ll try to help. Also, see the &#8220;Possibly Related Posts&#8221; below for related content on this topic.</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/04/tumblr-links-post-formats/">Permalink</a> | <a href="http://digwp.com/2011/04/tumblr-links-post-formats/#comments">16 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/04/tumblr-links-post-formats/&title=Tumblr Links with Post Formats">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/post-formats/" rel="tag">post-formats</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/04/tumblr-links-post-formats/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>New DiW Theme: Quantify</title>
		<link>http://digwp.com/2011/02/quantify-wordpress-theme/</link>
		<comments>http://digwp.com/2011/02/quantify-wordpress-theme/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 19:13:31 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Site News]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3621</guid>
		<description><![CDATA[Quantify is a clean, well-styled WordPress theme focused on usability and readability. Quantify is the base theme used for my new design, built with HTML5, liberal doses of CSS3, and a few jQuery snippets thrown in for good measure. Here is the demo, and here is a quick run-down of the features: Features Built with [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Quantify</strong> is a clean, well-styled WordPress theme focused on usability and readability. Quantify is the base theme used for my <a href="http://perishablepress.com/">new design</a>, built with <abbr title="Hypertext Markup Language">HTML</abbr>5, liberal doses of <abbr title="Cascade Style Sheets">CSS</abbr>3, and a few jQuery snippets thrown in for good measure. <a href="http://themeclubhouse.digwp.com/index.php?wptheme=Quantify" title="DiW Theme Clubhouse">Here is the demo</a>, and here is a quick run-down of the features:</p>
<p><span id="more-3621"></span></p>
<h3>Features</h3>
<ul>
<li>Built with all the latest and greatest stuff: WordPress, PHP, HTML5, CSS3, &amp; jQuery</li>
<li>Six <strong>custom fonts</strong> used throughout the design via CSS <code>@font-face</code> queries</li>
<li>Cross-browser compatible: looks awesome in modern browsers, works fine in older stuff</li>
<li>Three widgetized areas: header, sidebar, and footer</li>
<li>Smart sidebar functionality using Chris Coyier&rsquo;s <a href="http://css-tricks.com/more-sidebar/">More Sidebar</a> technique</li>
<li>Enhanced <a href="http://digwp.com/2009/07/making-an-expanding-code-box/" title="Making an Expanding Code Box">expanding code boxes</a> with lightbox-style sidebar hover effect</li>
<li>Firefox <a href="http://paulirish.com/2009/fighting-the-font-face-fout/" title="Fighting the @font-face FOUT"><abbr title="Flash of Unstyled Text">FOUT</abbr> fix</a> (Thanks to <a href="paul_irish">Paul Irish</a>)</li>
<li>Well-styled nested comments up to three levels deep</li>
<li>Comment markup entirely WordPress default template</li>
<li>Toggle-comments button to show/hide comments area</li>
<li>Lightweight and fast: design graphics embedded via data URLs</li>
<li>Clean WordPress theme template files and code</li>
<li>Custom <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/" title="WordPress functions.php Template with 15 Essential Custom Functions">functions.php</a> cleans up <code>&lt;head&gt;</code>, adds feed links, smart comment-reply &amp; jQuery inclusion</li>
<li>CSS print styles, for those special readers in your audience</li>
</ul>
<h3>Demo + How to get</h3>
<p>You can <a href=http://themeclubhouse.digwp.com/index.php?wptheme=Quantify"" title="DiW Theme Clubhouse">check out Quantify</a> at the Theme Clubhouse. Quantify is free for people who own <a href="http://digwp.com/" title="Learn How to WordPress">our book</a>, which is $27 and includes the following:</p>
<ul>
<li>Over 450 pages of hands-on, real-world WordPress action</li>
<li>Beautiful book design with tons of code snippets, tips &amp; tricks</li>
<li>All of our exclusive themes, including Quantify, All-Ajax, Plastique &amp; more</li>
<li>Access to our Members Area for secure downloads at your convenience</li>
<li><strong>Free book updates for life!</strong></li>
</ul>
<p>If you own the book, then <a href="http://digwp.com/wp-login.php">log in</a> to download Quantify or any of our themes. If you don&rsquo;t yet own the book, <a href="http://digwp.com/book/" title="Get the book!">go get it</a>!</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/02/quantify-wordpress-theme/">Permalink</a> | <a href="http://digwp.com/2011/02/quantify-wordpress-theme/#comments">15 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/02/quantify-wordpress-theme/&title=New DiW Theme: Quantify">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/book/" rel="tag">book</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/02/quantify-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Custom Login/Register/Password Code</title>
		<link>http://digwp.com/2010/12/login-register-password-code/</link>
		<comments>http://digwp.com/2010/12/login-register-password-code/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 06:30:08 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[Admin]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3102</guid>
		<description><![CDATA[In this DiW post, we transform three slices of code into a clean &#38; stylish tabbed menu that visitors can use to login, register, and recover passwords from anywhere in your site. Too many features &#38; details to explain up front, so check out the working demo to see the finished product. On the menu: [...]]]></description>
			<content:encoded><![CDATA[<p>In this <abbr title="Digging into WordPress">DiW</abbr> post, we transform three slices of code into a clean &amp; stylish tabbed menu that visitors can use to login, register, and recover passwords from anywhere in your site. Too many features &amp; details to explain up front, so <a href="http://digwp.com/custom-login-demo/" title="Custom Login Demo">check out the working demo</a> to see the finished product. On the menu:</p>
<p><span id="more-3102"></span></p>
<ul>
<li><a href="#default">Default WordPress Login Page</a></li>
<li><a href="#moving">Moving the login/register/password form</a></li>
<li><a href="#code">Custom WordPress template code</a></li>
<li><a href="#demo">Implement and Demo</a></li>
<li><a href="#custom">Customizing things</a></li>
<li><a href="#wrap">Wrap up</a></li>
</ul>
<h3 id="default">Default WordPress Login Page</h3>
<p>Out of the box, WordPress uses <code>wp-login.php</code> for logging into the Admin, retrieving lost passwords, and registering for site membership. Each of these activities are handled on the same page, commonly referred to as the WordPress Login Page. </p>
<p><img src="http://digwp.com/wp-content/blog-images/custom-login-01.jpg" alt="[ Screenshot: Default WordPress Login/Register Page ]" /><br /><small>Yep, it&rsquo;s the WordPress Login Page</small></p>
<p>As seen here, the Login Page shows the log-in form by default. Beneath the form are two links, &ldquo;Register&rdquo; and &ldquo;Lost your password?&rdquo;, which enable users to (yep, you guessed it) register and recover their password. </p>
<p>The cool thing about the Login Page is that the page doesn&rsquo;t reload when either of these links are clicked. Instead, the form instantly changes from login to register or password to whatever. All three forms are included on the <code>wp-login.php</code> page and hidden/revealed as-needed using JavaScript. This &ldquo;same-page&rdquo; functionality is key to setting up our own custom login/register/password form elsewhere in our theme.</p>
<h3 id="moving">Moving the login/register/password form</h3>
<p>While it&rsquo;s not a good idea to move the entire <code>wp-login.php</code> file, it is possible to display the login/register/password forms anywhere in your theme. For example, putting the forms in your <code>sidebar.php</code> make it super-easy for visitors to register and login from anywhere in your site (here is an <a href="http://angry-birds.net/" title="Angry Birds Galaxy">example</a>). You could even create a WordPress page for each event: login, registration, and password-recovery pages that are customized/optimized in some really unique, bad-ass way.</p>
<p>The key to mobilizing the login forms is ensuring that they&rsquo;ll work properly regardless of placement (before, after, or within the loop) in your theme template files. We also want to ensure that normal visitors who aren&rsquo;t logged in see the forms, but logged-in users do not (or see alternate content). </p>
<p>Basically, it should work exactly like the default WordPress login functionality, but with one exception: instead of redirecting to the Admin Area (for log-ins) or to the Login Page (for registrations/password-recovery), we want the user to <em>remain on the same page</em>. This enables your guests to log-in, register, and reset passwords without leaving whatever page they happen to be visiting. Here&rsquo;s the code to make it happen..</p>
<h3 id="code">Custom WordPress template code</h3>
<p>Here is the code to display the login/register/password form anywhere in your theme:</p>
<p><a href="http://digwp.com/examples/CustomLoginCode/custom-login-02.txt" title="Custom Login/Register/Password Code">view as plain text</a>
<pre><code>&lt;div id="login-register-password"&gt;

	&lt;?php global $user_ID, $user_identity; get_currentuserinfo(); if (!$user_ID) { ?&gt;

	&lt;ul class="tabs_login"&gt;
		&lt;li class="active_login"&gt;&lt;a href="#tab1_login"&gt;Login&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="#tab2_login"&gt;Register&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="#tab3_login"&gt;Forgot?&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;div class="tab_container_login"&gt;
		&lt;div id="tab1_login" class="tab_content_login"&gt;

			&lt;?php $register = $_GET['register']; $reset = $_GET['reset']; if ($register == true) { ?&gt;

			&lt;h3&gt;Success!&lt;/h3&gt;
			&lt;p&gt;Check your email for the password and then return to log in.&lt;/p&gt;

			&lt;?php } elseif ($reset == true) { ?&gt;

			&lt;h3&gt;Success!&lt;/h3&gt;
			&lt;p&gt;Check your email to reset your password.&lt;/p&gt;

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

			&lt;h3&gt;Have an account?&lt;/h3&gt;
			&lt;p&gt;Log in or sign up! It&amp;rsquo;s fast &amp;amp; &lt;em&gt;free!&lt;/em&gt;&lt;/p&gt;

			&lt;?php } ?&gt;

			&lt;form method="post" action="&lt;?php bloginfo('url') ?&gt;/wp-login.php" class="wp-user-form"&gt;
				&lt;div class="username"&gt;
					&lt;label for="user_login"&gt;&lt;?php _e('Username'); ?&gt;: &lt;/label&gt;
					&lt;input type="text" name="log" value="&lt;?php echo esc_attr(stripslashes($user_login)); ?&gt;" size="20" id="user_login" tabindex="11" /&gt;
				&lt;/div&gt;
				&lt;div class="password"&gt;
					&lt;label for="user_pass"&gt;&lt;?php _e('Password'); ?&gt;: &lt;/label&gt;
					&lt;input type="password" name="pwd" value="" size="20" id="user_pass" tabindex="12" /&gt;
				&lt;/div&gt;
				&lt;div class="login_fields"&gt;
					&lt;div class="rememberme"&gt;
						&lt;label for="rememberme"&gt;
							&lt;input type="checkbox" name="rememberme" value="forever" checked="checked" id="rememberme" tabindex="13" /&gt; Remember me
						&lt;/label&gt;
					&lt;/div&gt;
					&lt;?php do_action('login_form'); ?&gt;
					&lt;input type="submit" name="user-submit" value="&lt;?php _e('Login'); ?&gt;" tabindex="14" class="user-submit" /&gt;
					&lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;" /&gt;
					&lt;input type="hidden" name="user-cookie" value="1" /&gt;
				&lt;/div&gt;
			&lt;/form&gt;
		&lt;/div&gt;
		&lt;div id="tab2_login" class="tab_content_login" style="display:none;"&gt;
			&lt;h3&gt;Register for this site!&lt;/h3&gt;
			&lt;p&gt;Sign up now for the good stuff.&lt;/p&gt;
			&lt;form method="post" action="&lt;?php echo site_url('wp-login.php?action=register', 'login_post') ?&gt;" class="wp-user-form"&gt;
				&lt;div class="username"&gt;
					&lt;label for="user_login"&gt;&lt;?php _e('Username'); ?&gt;: &lt;/label&gt;
					&lt;input type="text" name="user_login" value="&lt;?php echo esc_attr(stripslashes($user_login)); ?&gt;" size="20" id="user_login" tabindex="101" /&gt;
				&lt;/div&gt;
				&lt;div class="password"&gt;
					&lt;label for="user_email"&gt;&lt;?php _e('Your Email'); ?&gt;: &lt;/label&gt;
					&lt;input type="text" name="user_email" value="&lt;?php echo esc_attr(stripslashes($user_email)); ?&gt;" size="25" id="user_email" tabindex="102" /&gt;
				&lt;/div&gt;
				&lt;div class="login_fields"&gt;
					&lt;?php do_action('register_form'); ?&gt;
					&lt;input type="submit" name="user-submit" value="&lt;?php _e('Sign up!'); ?&gt;" class="user-submit" tabindex="103" /&gt;
					&lt;?php $register = $_GET['register']; if($register == true) { echo '&lt;p&gt;Check your email for the password!&lt;/p&gt;'; } ?&gt;
					&lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;?register=true" /&gt;
					&lt;input type="hidden" name="user-cookie" value="1" /&gt;
				&lt;/div&gt;
			&lt;/form&gt;
		&lt;/div&gt;
		&lt;div id="tab3_login" class="tab_content_login" style="display:none;"&gt;
			&lt;h3&gt;Lose something?&lt;/h3&gt;
			&lt;p&gt;Enter your username or email to reset your password.&lt;/p&gt;
			&lt;form method="post" action="&lt;?php echo site_url('wp-login.php?action=lostpassword', 'login_post') ?&gt;" class="wp-user-form"&gt;
				&lt;div class="username"&gt;
					&lt;label for="user_login" class="hide"&gt;&lt;?php _e('Username or Email'); ?&gt;: &lt;/label&gt;
					&lt;input type="text" name="user_login" value="" size="20" id="user_login" tabindex="1001" /&gt;
				&lt;/div&gt;
				&lt;div class="login_fields"&gt;
					&lt;?php do_action('login_form', 'resetpass'); ?&gt;
					&lt;input type="submit" name="user-submit" value="&lt;?php _e('Reset my password'); ?&gt;" class="user-submit" tabindex="1002" /&gt;
					&lt;?php $reset = $_GET['reset']; if($reset == true) { echo '&lt;p&gt;A message will be sent to your email address.&lt;/p&gt;'; } ?&gt;
					&lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;?reset=true" /&gt;
					&lt;input type="hidden" name="user-cookie" value="1" /&gt;
				&lt;/div&gt;
			&lt;/form&gt;
		&lt;/div&gt;
	&lt;/div&gt;

	&lt;?php } else { // is logged in ?&gt;

	&lt;div class="sidebox"&gt;
		&lt;h3&gt;Welcome, &lt;?php echo $user_identity; ?&gt;&lt;/h3&gt;
		&lt;div class="usericon"&gt;
			&lt;?php global $userdata; get_currentuserinfo(); echo get_avatar($userdata-&gt;ID, 60); ?&gt;

		&lt;/div&gt;
		&lt;div class="userinfo"&gt;
			&lt;p&gt;You&amp;rsquo;re logged in as &lt;strong&gt;&lt;?php echo $user_identity; ?&gt;&lt;/strong&gt;&lt;/p&gt;
			&lt;p&gt;
				&lt;a href="&lt;?php echo wp_logout_url('index.php'); ?&gt;"&gt;Log out&lt;/a&gt; | 
				&lt;?php if (current_user_can('manage_options')) { 
					echo '&lt;a href="' . admin_url() . '"&gt;' . __('Admin') . '&lt;/a&gt;'; } else { 
					echo '&lt;a href="' . admin_url() . 'profile.php"&gt;' . __('Profile') . '&lt;/a&gt;'; } ?&gt;

			&lt;/p&gt;
		&lt;/div&gt;
	&lt;/div&gt;

	&lt;?php } ?&gt;

&lt;/div&gt;
</code></pre>
<p>Okay, so here are the functional highlights for this hefty chunk of code:</p>
<ul>
<li>Everything is wrapped with <code>&lt;div id="login-register-password"&gt;&lt;/div&gt;</code></li>
<li>If the user is <em>not</em> logged in, the three forms are <em>included</em> in the markup</li>
<li>If the user <em>is</em> logged in, a simple welcome message is displayed</li>
<li>Success messages are displayed after both password recovery and registration</li>
<li>Each form submission sets a generic <code>user-cookie</code></li>
<li>After login or registration, the script redirects the user to the same page</li>
<li>Only one form is shown at a time; JavaScript is used to show and hide forms</li>
</ul>
<p>So if you just throw this thing into your <code>sidebar.php</code> file, you&rsquo;ll see the login form and three links: login, register, and recover-password. The other two forms are included in the markup, but are hidden with <abbr title="Cascading Style Sheets">CSS</abbr> (<code>display:none;</code>). As-is, the three links won&rsquo;t do anything because they require JavaScript to work. Once we sprinkle in some jQuery, the links will toggle the three different forms.</p>
<h3 id="demo">Implement and Demo</h3>
<p>First let&rsquo;s walk through using this code in your theme, and then we&rsquo;ll check out a demo.</p>
<ol>
<li>Place the <a href="http://digwp.com/examples/CustomLoginCode/custom-login-02.txt" title="Custom Login/Register/Password Code">custom login code</a> in your <code>sidebar.php</code> file, or some other location</li>
<li>Grab the <a href="http://digwp.com/examples/CustomLoginCode/custom-login-01.txt" title="jQuery Code">jQuery code</a> (no-conflict mode) and include it in your <code>footer.php</code> file</li>
<li>Include the <a href="http://digwp.com/examples/CustomLoginCode/custom-login-03.txt" title="CSS Code">CSS code</a> in your theme&rsquo;s <code>style.css</code> file, or wherever your styles are located</li>
</ol>
<p>..and done. Once these three items are in place, upload everything to your server and check it out. Here is a <strong><a href="http://digwp.com/custom-login-demo/" title="Custom Login Demo">demo</a></strong> showing this code used on a custom page <em>within</em> the loop. </p>
<p>Note that we have registration disabled here at <a href="http://digwp.com/" title="Digging into WordPress">DigWP.com</a>, so the forms won&rsquo;t be of much use other than to show how the tabs work and how the forms are styled. Here are some screenshots showing the &ldquo;success&rdquo; messages, and also the &ldquo;logged-in&rdquo; display.</p>
<p><img src="http://digwp.com/wp-content/blog-images/custom-login-02.gif" alt="[ Screenshot: Registration Success Message ]" /><br /><small>Message displayed on successful registration</small></p>
<p><img src="http://digwp.com/wp-content/blog-images/custom-login-03.gif" alt="[ Screenshot: Password-Recovery Success Message ]" /><br /><small>Message displayed on successful password-recovery</small></p>
<p><img src="http://digwp.com/wp-content/blog-images/custom-login-04.gif" alt="[ Screenshot: Logged-In View ]" /><br /><small>Content displayed when user is logged into the site</small></p>
<p>Here again is the <a href="http://digwp.com/custom-login-demo/" title="Custom Login Demo">demo</a> and here are the three resource files:</p>
<ul>
<li><a href="http://digwp.com/examples/CustomLoginCode/custom-login-01.txt" title="Custom Login/Register/Password Code">Custom Template Code</a></li>
<li><a href="http://digwp.com/examples/CustomLoginCode/custom-login-02.txt" title="jQuery Code">jQuery Code</a></li>
<li><a href="http://digwp.com/examples/CustomLoginCode/custom-login-03.txt" title="CSS Code">CSS Code</a></li>
</ul>
<h3 id="custom">Customizing things</h3>
<p>One of the main reasons why we like working with actual code instead of widgets or plugins is the ability to easily customize anything we want exactly how we want it. With this implementation, there are basically three things to customize: the jQuery, the custom login code, and the <abbr title="Cascading Style Sheets">CSS</abbr>. As with any code, there are countless ways to modify appearance and functionality, so hopefully you have something specific in mind, and are familiar enough with design to jump in and customize things. If not, no worries &ndash; here are some ideas to help get you started.</p>
<h4>Customizing the login forms</h4>
<p>As-is, the custom login forms redirect to the current page. To get any/all of the forms to redirect to a different page, locate and edit the following line of code:</p>
<pre><code>&lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;" /&gt;</code></pre>
<p>There are three instances of this hidden input field, which WordPress uses to perform the redirect. The <code>value</code> returns the current <abbr title="Uniform Resource Locator">URL</abbr>, so that&rsquo;s what needs changed for each form to redirect elsewhere.</p>
<p>Another useful modification involves customizing what the logged-in users see. Showing the gravatar and username is kind of neat, but there are tons of cool tricks to help ensure smooth user experience.</p>
<h4>Customizing the jQuery</h4>
<p>The jQuery used to show/hide the different login panels is actually pretty basic and is only used for toggling display states. I suppose there is a way to customize this, but it already handles additional menu items, so maybe you want to change the class names or optimize the script or something.</p>
<p>I do love to look at a nice slice of well-formatted jQuery, however, so I&rsquo;ll further indulge myself by including the entire code snippet right here:</p>
<pre><code>&lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
	$(document).ready(function() {
		$(".tab_content_login").hide();
		$("ul.tabs_login li:first").addClass("active_login").show();
		$(".tab_content_login:first").show();
		$("ul.tabs_login li").click(function() {
			$("ul.tabs_login li").removeClass("active_login");
			$(this).addClass("active_login");
			$(".tab_content_login").hide();
			var activeTab = $(this).find("a").attr("href");
			if ($.browser.msie) {$(activeTab).show();}
			else {$(activeTab).show();}
			return false;
		});
	});
&lt;/script&gt;</code></pre>
<p>A bit heavy-handed perhaps, but works great with no editing required ;)</p>
<h4>Customizing the CSS</h4>
<p>To get that fancy tabbed form menu looking all clean and rounded, <em>much</em> <abbr title="Cascading Style Sheets">CSS</abbr> is used. So instead of posting endless gobs of <abbr title="Cascading Style Sheets">CSS</abbr>, here is the <a href="http://digwp.com/examples/CustomLoginCode/custom-login-03.txt" title="CSS Code">code in plain text</a>. As with any <abbr title="Cascading Style Sheets">CSS</abbr>, the best way to customize things is to open Firebug and start tweaking.</p>
<h4>Just the links</h4>
<p>One last trick: use this code to display <em>links</em> to the default WordPress login/registration page:</p>
<pre><code>&lt;ul&gt;
	&lt;?php wp_register(); ?&gt;
	&lt;li&gt;&lt;?php wp_loginout(); ?&gt;&lt;/li&gt;
	&lt;?php wp_meta(); ?&gt;
&lt;/ul&gt;</code></pre>
<p>Nothing to golf about, but I figured it was worth mentioning.</p>
<h3 id="wrap">Wrap up</h3>
<p>Using the code and techniques in this article, you can provide your readers with a login form anywhere on your site. This makes it easy for your users and visitors to login/logout, register for your site, and recover passwords without leaving their current page. The login code works great as-is or is easily transformed into a snazzily tabbed login menu using a sprinkle of <abbr title="Cascading Style Sheets">CSS</abbr> and a dash of jQuery.</p>
<p>Finally, one of the great things about WordPress is that there is always more than one way to set things up. So if you see a way to improve the code, please share with the community by leaving a comment. Thank you!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/12/login-register-password-code/">Permalink</a> | <a href="http://digwp.com/2010/12/login-register-password-code/#comments">60 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/12/login-register-password-code/&title=Custom Login/Register/Password Code">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/admin/" rel="tag">Admin</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/12/login-register-password-code/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>Call a Widget with a Shortcode</title>
		<link>http://digwp.com/2010/04/call-widget-with-shortcode/</link>
		<comments>http://digwp.com/2010/04/call-widget-with-shortcode/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 17:30:03 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1752</guid>
		<description><![CDATA[We covered how to run a shortcode in a widget. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably [...]]]></description>
			<content:encoded><![CDATA[<p>We covered how to <a href="http://digwp.com/2010/03/shortcodes-in-widgets/">run a shortcode in a widget</a>. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably a custom page template for that widgetized area and such. I wanted to just put [widget widget_name="my_widget"] in the pages content and have that widget pop in. Turns out it wasn&#8217;t as easy I wanted it to be, but it&#8217;s not that bad&#8230;</p>
<p><span id="more-1752"></span></p>
<p>The answer was creating a custom function for the functions.php file which would output any widget by name. There is a function just for that: <code>the_widget()</code> (<a href="http://codex.wordpress.org/Template_Tags/the_widget">incomplete codex page</a>).</p>
<h3>The logic</h3>
<ol>
<li>Test if widget exists</li>
<li>If it does&#8230;
<ol>
<li>Start capturing output</li>
<li>Output widget</li>
<li>End capturing output</li>
<li>Return captured output</li>
</ol>
</li>
<li>If it doesn&#8217;t exist&#8230;
<ol>
<li>Output fail message</li>
</ol>
</li>
</ol>
<h3>The code for functions.php</h3>
<pre><code>function widget($atts) {
    
    global $wp_widget_factory;
    
    extract(shortcode_atts(array(
        'widget_name' =&gt; FALSE
    ), $atts));
    
    $widget_name = wp_specialchars($widget_name);
    
    if (!is_a($wp_widget_factory-&gt;widgets[$widget_name], 'WP_Widget')):
        $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
        
        if (!is_a($wp_widget_factory-&gt;widgets[$wp_class], 'WP_Widget')):
            return '&lt;p&gt;'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'&lt;strong&gt;'.$class.'&lt;/strong&gt;').'&lt;/p&gt;';
        else:
            $class = $wp_class;
        endif;
    endif;
    
    ob_start();
    the_widget($widget_name, $instance, array('widget_id'=&gt;'arbitrary-instance-'.$id,
        'before_widget' =&gt; '',
        'after_widget' =&gt; '',
        'before_title' =&gt; '',
        'after_title' =&gt; ''
    ));
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
    
}
add_shortcode('widget','widget'); </code></pre>
<h3>Usage</h3>
<p>Now in Post/Page content, you can use the widget just by referencing it by name:</p>
<pre><code>[widget widget_name="Your_Custom_Widget"]</code></pre>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/04/call-widget-with-shortcode/">Permalink</a> | <a href="http://digwp.com/2010/04/call-widget-with-shortcode/#comments">15 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/04/call-widget-with-shortcode/&title=Call a Widget with a Shortcode">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/04/call-widget-with-shortcode/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>WordPress Custom functions.php Template, Part 2</title>
		<link>http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/</link>
		<comments>http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 16:13:36 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1811</guid>
		<description><![CDATA[In a recent post, we show you how to clean up and enhance the functionality of WordPress with a custom functions.php template. In that post, we explain how using a custom functions.php template can speed up development while optimizing many key aspects of WordPress. In this post, we deliver another prime collection of 15 custom [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent post, we show you how to clean up and enhance the functionality of WordPress with a <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/" title="WordPress functions.php Template with 15 Essential Custom Functions">custom functions.php template</a>. In <em>that</em> post, we explain how using a custom <code>functions.php</code> template can speed up development while optimizing many key aspects of WordPress. In <em>this</em> post, we deliver another prime collection of <strong>15 custom functions to enhance your WordPress site</strong>. These functions provide all sorts of useful functionality, including stuff like:</p>
<ul>
<li>Callback function for a custom comments loop</li>
<li>Automatic content insertion in posts and feeds</li>
<li>Spam and delete links for comments when logged in</li>
<li>Buffer period before new posts are added to your feeds</li>
<li>Including an Admin link to the &ldquo;All-Settings&rdquo; page</li>
<li>Removing the version and generator information from your site and feed</li>
</ul>
<p>These new functions <em>extend</em> the functionality of our original <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/" title="WordPress functions.php Template with 15 Essential Custom Functions">functions.php template</a> with <strong>15 more useful functions</strong>. Not everything presented here is going to be necessary for <em>all</em> of your themes, so just grab what you need and add it your own custom <code>functions.php</code> file.</p>
<p><span id="more-1811"></span></p>
<blockquote><p>In this <acronym title="Digging into WordPress">DiW</acronym> article, we extend our original functions.php template with 15 more useful functions.</p></blockquote>
<p>As before, we&rsquo;ll first walk through each of the functions and then unify them into a working <code>functions.php</code> template. To use, just copy and paste the template code at the end of this article or <a href="#functions-download" title="Download the zipped template file">grab a copy of the zipped functions.php file</a> and enjoy a custom collection of functions that will help you <strong>optimize your development process</strong> while enhancing WordPress with some <strong>awesome new functionality</strong>.</p>
<h3>Insert custom content after each post</h3>
<p>If you look at the different things contained within a typical post, you will find many common and repetitive items, such as feed links, copyright information, and <a href="http://perishablepress.com/press/2008/11/23/fully-valid-seo-friendly-social-media-links-for-wordpress/" title="Fully Valid, SEO-Friendly Social Media Links for WordPress">social-media bookmarks</a>. While there&rsquo;s nothing wrong with inserting this content into your <code>single.php</code> template, it is sometimes easier to manage things from the <code>functions.php</code> file. For example, at <a href="http://perishablepress.com/" title="Digital Design and Dialogue">Perishable Press</a>, I include a brief copyright statement at the end of each post. By including the following code in my <code>functions.php</code> template, it&rsquo;s something that happens automatically:</p>
<pre><code>// add custom post content
function add_post_content($content) {
	if(!is_feed() &amp;&amp; !is_home()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_content', 'add_post_content');</code></pre>
<p>The trick here is an old one, but it&rsquo;s extremely useful. By changing the line beginning with &ldquo;<code>$content.</code>&rdquo;, you can add just about any content you like.</p>
<h3>Insert custom content in your feeds</h3>
<p>Just as with the previous method, this function makes it possible to automatically add any content to your feeds. Yes, I know there are plugins that will <a href="http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/" title="Wordpress Plugin : Better Feed">make your feed footers do backflips</a>, but for a simple copyright message or other info, I think it is easier and more efficient to simply toss a few lines into your custom <code>functions.php</code> template:</p>
<pre><code>// add custom feed content
function add_feed_content($content) {
	if(is_feed()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_excerpt_rss', 'add_feed_content');
add_filter('the_content', 'add_feed_content');</code></pre>
<p>As before, you can change the added content to whatever you want by editing the &ldquo;<code>$content</code>&rdquo; variable. Once in place, this will append a dynamic copyright message to each post in your feed. Note: if you happen to be adding the same content to your web pages (using the previous method) <em>and</em> your feeds (using this method), you may combine the two functions like so:</p>
<pre><code>// add custom content to feeds and posts
function add_custom_content($content) {
	if(!is_home()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_excerpt_rss', 'add_custom_content');
add_filter('the_content', 'add_custom_content');</code></pre>
<p>Remember that if you use this combined function that you should remove or comment out both of the individual ones to avoid duplicate output. It will be included but commented out in the complete <code>functions.php</code> template file.</p>
<h3>Completely remove the version number from pages and feeds</h3>
<p>A commonly cited <a href="http://digwp.com/2009/07/remove-wordpress-version-number/" title="How to Remove the WordPress Version Number (The Right Way)">security measure for WordPress-powered sites</a> involves removing the automatically generated version number from appearing in the <code>&lt;head&gt;</code> section of your pages&rsquo; source code. This type of security technique is referred to as &ldquo;security through obscurity,&rdquo; and aims at hiding potentially sensitive information from a would-be attacker. Here&rsquo;s a function that does the job:</p>
<pre><code>// remove version info from head and feeds
function complete_version_removal() {
	return '';
}
add_filter('the_generator', 'complete_version_removal');</code></pre>
<p>This will remove your site&rsquo;s version and generator information from all of your pages and feeds, making it a little bit harder for the bad guys and a little bit safer for you and your visitors.</p>
<h3>Customize the admin footer message</h3>
<p>Customization is what makes your online experience something special. For your own sites and for your clients&rsquo; sites, it is nice to customize the generic admin footer message with something a little more useful, informative, and inspiring. This little gem makes it easy:</p>
<pre><code>// customize admin footer text
function custom_admin_footer() {
	echo '&lt;a href="http://monzilla.biz/"&gt;Website Design by Monzilla Media&lt;/a&gt;';
} 
add_filter('admin_footer_text', 'custom_admin_footer');</code></pre>
<p>Here, for the sake of example, we are including a link to my web-design company, but you can customize the content with just about anything you wish. If this were something I had to do manually for each site, I probably wouldn&rsquo;t do it. But by adding these few lines to my <code>functions.php</code> template, it all happens automatically, without me having to think about it. Nice&nbsp;;)</p>
<h3>Enable HTML markup in user profiles</h3>
<p>When customizing their profiles, users may want to include a hyperlink, bold text, or some other <acronym title="Hypertext markup language">HTML</acronym> markup. By default, WordPress prevents this from happening, but you can easily enable it with this friendly little snippet:</p>
<pre><code>// enable html markup in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');</code></pre>
<p><strong>Note:</strong> as <a href="#comment-4171" title="Jump to comment">miqrogroove</a> points out, enabling <acronym title="Hypertext markup language">HTML</acronym> may be best left to sites that have open user-registration disabled. Use with discretion.</p>
<h3>Delay feed update after posting</h3>
<p>As a chronic perfectionist, I hate it when I post something only to discover an error a few minutes later. By the time I notice, fix and update the post, it&rsquo;s already been beamed out all over the freakin&rsquo; place. To prevent this, I like to take the advice of <a href="http://wpengineer.com/publish-the-feed-later/" title="Publish The Feed Later">WPEngineer</a> and give myself a little buffer period or &ldquo;safety net&rdquo; after publishing my posts.</p>
<pre><code>// delay feed update
function publish_later_on_feed($where) {
	global $wpdb;

	if (is_feed()) {
		// timestamp in WP-format
		$now = gmdate('Y-m-d H:i:s');

		// value for wait; + device
		$wait = '5'; // integer

		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
		$device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

		// add SQL-sytax to default $where
		$where .= " AND TIMESTAMPDIFF($device, $wpdb-&gt;posts.post_date_gmt, '$now') &gt; $wait ";
	}
	return $where;
}
add_filter('posts_where', 'publish_later_on_feed');</code></pre>
<p>This code quietly and automatically gives me an extra five minutes before my post is added to my feeds. If you need more or less than five minutes, just edit the &ldquo;<code>$wait</code>&rdquo; variable with the integer of your choice.</p>
<h3>Add an Admin link to the WordPress &ldquo;All-Settings&rdquo; page</h3>
<p>As we&rsquo;ve explained before, WordPress makes it easy to <a href="http://digwp.com/2009/06/edit-your-database-options-from-the-wordpress-admin/" title="Edit Your Database Options from the WordPress Admin">view and edit your blog settings from the Admin area</a>. Thanks to a file named &ldquo;<code>options.php</code>&rdquo;, WordPress will display all of your database settings and enable you to edit a majority of them. To view this page, you need to log in as Admin and enter this <acronym title="Uniform Resource Locator">URL</acronym> in your browser&rsquo;s address bar:</p>
<p><code>http://domain.tld/wp-admin/options.php</code></p>
<p>Having access to your &ldquo;All-Settings&rdquo; page can be extremely helpful, so it&rsquo;s nice to display a direct link for easy access. The following slice of code in your <code>functions.php</code> file is all that&rsquo;s needed:</p>
<pre><code>// admin link for all settings
function all_settings_link() {
	add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
add_action('admin_menu', 'all_settings_link');</code></pre>
<p>Once in place, you will see a link to your &ldquo;All Settings&rdquo; page in the WordPress Admin. You can change the name of the link to whatever you prefer by editing the two instances of &ldquo;All Settings&rdquo;.</p>
<h3>Remove all nofollow attributes from comments</h3>
<p>There are <a href="http://perishablepress.com/press/2007/09/23/much-ado-about-nofollow-the-perishable-press-dofollow-series/" title="Much ado about nofollow: The Perishable Press Dofollow Series">a million ways</a> to <a href="http://perishablepress.com/press/2007/09/05/comprehensive-reference-for-wordpress-no-nofollow-dofollow-plugins/" title="Comprehensive Reference for WordPress NoNofollow/Dofollow Plugins">remove nofollow</a> from your comments, but nothing is as <em>easy</em> as this method provided by code guru <a href="http://toscho.de/2009/no-no-no-nofollow/" title="No no no nofollow">Thomas Scholz</a>:</p>
<pre><code>// remove nofollow from comments
function xwp_dofollow($str) {
	$str = preg_replace(
		'~&lt;a ([^&gt;]*)\s*(["|\']{1}\w*)\s*nofollow([^&gt;]*)&gt;~U',
		'&lt;a ${1}${2}${3}&gt;', $str);
	return str_replace(array(' rel=""', " rel=''"), '', $str);
}
remove_filter('pre_comment_content',     'wp_rel_nofollow');
add_filter   ('get_comment_author_link', 'xwp_dofollow');
add_filter   ('post_comments_link',      'xwp_dofollow');
add_filter   ('comment_reply_link',      'xwp_dofollow');
add_filter   ('comment_text',            'xwp_dofollow');</code></pre>
<p>That code will remove all instances of the nefarious &ldquo;<code>nofollow</code>&rdquo; attribute from <em>all</em> comment items, including the author link and comment text. This is a great way to automatically remove nofollow with no plugins or hacking required.</p>
<h3>Enable easy display of your post&rsquo;s word count</h3>
<p>This function enables you to display your post&rsquo;s word count without cluttering up the WordPress loop. To display the word count of your posts, first place this in your <code>functions.php</code> file:</p>
<pre><code>// count words in posts
function word_count() {
	global $post;
	echo str_word_count($post-&gt;post_content);
}</code></pre>
<p>Then, simply place this anywhere in your loop where you would like the number to appear:</p>
<p><code>&lt;?php word_count(); ?&gt;</code></p>
<p>So for example, you could display your post&rsquo;s word count to your visitors with something like:</p>
<p><code>&lt;p&gt;This post contains a whopping &lt;?php word_count(); ?&gt; words.&lt;/p&gt;</code></p>
<p>We can also easily display the word count of other items, such as the post title:</p>
<p><code>&lt;?php echo str_word_count($post-&gt;post_title); ?&gt;</code></p>
<p>Likewise, we can exclude the function from <code>functions.php</code> and get the word count with a single line of code in the loop:</p>
<p><code>&lt;?php echo str_word_count($post-&gt;post_content); ?&gt;</code></p>
<p>Just slap &lsquo;em anywhere in your post loop to display your word count. Not always needed, but nice to have available&nbsp;;)</p>
<h3>Enable delete and spam links for comments</h3>
<p>Managing your comments is easily done via the Admin, but geeks like me also like to see things from the outside, as they appear to the public. Browsing through comments as they appear on your site helps you catch things that may have eluded routine approvals in the Admin&rsquo;s comment listings. To help facilitate this process, I like to include a <a href="http://perishablepress.com/press/2008/12/01/spam-delete-buttons-links-for-old-versions-wordpress/" title="Backwards-Compatible Spam and Delete Buttons for WordPress">backwards-compatible set of spam and delete links</a> next to each comment. This makes it super-easy to cultivate comments live on the site.</p>
<pre><code>// spam &amp; delete links for all versions of wordpress
function delete_comment_link($id) {
	if (current_user_can('edit_post')) {
		echo '| &lt;a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&amp;c='.$id.'"&gt;del&lt;/a&gt; ';
		echo '| &lt;a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&amp;dt=spam&amp;c='.$id.'"&gt;spam&lt;/a&gt;';
	}
}</code></pre>
<p>Once this is included in your <code>functions.php</code> file, displaying the links is as easy as adding this to your comments loop:</p>
<pre><code>&lt;?php delete_comment_link(get_comment_ID()); ?&gt;</code></pre>
<h3>Disable all WordPress feeds</h3>
<p>Thanks to <a href="http://wpengineer.com/disable-wordpress-feed/" title="How to Disable RSS Feeds in WordPress">Frank from WPEngineer</a>, it is easy to disable all feed functionality for your site. Here is the <code>functions.php</code> code:</p>
<p><strong>Note:</strong> Only use this function if you want to <em>disable</em> your feeds! This function will be commented out of the complete <code>functions.php</code> file.</p>
<pre><code>// disable all feeds
function fb_disable_feed() {
	wp_die(__('&lt;h1&gt;Feed not available, please visit our &lt;a href="'.get_bloginfo('url').'"&gt;Home Page&lt;/a&gt;!&lt;/h1&gt;'));
}
add_action('do_feed',      'fb_disable_feed', 1);
add_action('do_feed_rdf',  'fb_disable_feed', 1);
add_action('do_feed_rss',  'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1);</code></pre>
<p>This function will quietly and completely disable all of your site&rsquo;s feeds, including all different formats. With this code in place, any request for your feed will return the following message in a nice, big set of <code>&lt;h1&gt;</code> tags:</p>
<blockquote><p>Feed not available, please visit our <a href="http://digwp.com/">Home Page</a>!</p></blockquote>
<p>This message is easily customized by editing the &ldquo;<code>wp_die</code>&rdquo; argument in the function.</p>
<h3>Customize the default gravatars and add your own</h3>
<p>Instead of suffering with the rather dull default gravatars, use this code to customize your own: </p>
<pre><code>// customize default gravatars
function custom_gravatars($avatar_defaults) {

	// change the default gravatar
	$customGravatar1 = get_bloginfo('template_directory').'/images/gravatar-01.png';
	$avatar_defaults[$customGravatar1] = 'Default';

	// add a custom user gravatar
	$customGravatar2 = get_bloginfo('template_directory').'/images/gravatar-02.png';
	$avatar_defaults[$customGravatar2] = 'Custom Gravatar';

	// add another custom gravatar
	$customGravatar3 = get_bloginfo('template_directory').'/images/gravatar-03.png';
	$avatar_defaults[$customGravatar3] = 'Custom gravatar';

	return $avatar_defaults;
}
add_filter('avatar_defaults', 'custom_gravatars');</code></pre>
<p>Of course, you can manually choose a default gravatar by specifying its location via the &ldquo;<code>get_avatar</code>&rdquo; template tag, but this method makes it <em>so</em> much easier. Not only does it replace the default with <em>multiple</em> custom gravatars, but it also goes the extra mile by displaying them in the WordPress Admin area under <strong>Settings &gt; Discussion</strong>. From there, you can select any of your custom gravatars by simply selecting it and clicking the &ldquo;Update&rdquo; button. Nothing could be easier. </p>
<p>A few notes about this function:</p>
<ul>
<li>As is, it adds three new gravatars to choose as defaults.</li>
<li>Each gravatar should be located in your theme&rsquo;s <code>images</code> directory.</li>
<li>You can add as many default gravatars as you would like by emulating the code pattern.</li>
<li>If you keep your custom gravatars someplace else, be sure and edit the image paths accordingly.</li>
</ul>
<h3>Disable automatic formatting in post content via shortcode</h3>
<p><a href="http://www.wprecipes.com/disable-wordpress-automatic-formatting-on-posts-using-a-shortcode" title="Disable WordPress automatic formatting on posts using a shortcode">WPRecipes</a> shows us how to prevent WordPress from automatically formatting chunks of post content by using a shortcode. This is very useful for posting code, poetry, or anything else that you would like to display in raw format. To do this, we add the following snippet to our <code>functions.php</code> file:</p>
<pre><code>// disable auto formatting in posts
function my_formatter($content) {
	$new_content = '';
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

	foreach ($pieces as $piece) {
		if (preg_match($pattern_contents, $piece, $matches)) {
			$new_content .= $matches[1];
		} else {
			$new_content .= wptexturize(wpautop($piece));
		}
	}

	return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'my_formatter', 99);</code></pre>
<p>With that code in place, you can insert unformatted code into your posts via the &ldquo;<code>[raw]</code>&rdquo; shortcode, for example:</p>
<p><code>[raw]Unformatted content[/raw]</code></p>
<p>Anything contained within those shortcodes will be left unformatted when displayed in your posts.</p>
<h3>Escape HTML entities in comments</h3>
<p><a href="http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/" title="Automatically Escape HTML Entities of Code Fragments in Comments">Kaspars Dambis</a> shows us how to automatically escape encoded <acronym title="Hypertext markup Language">HTML</acronym> entities in the comments that readers leave on your posts. This is especially useful for blogs that deal in heavy code exchanges on post threads. This enables your commentators to simply wrap their code in <code>&lt;code&gt;</code> tags and not have to worry about manually converting characters such as angled brackets (&ldquo;<code>&lt;</code>&rdquo; &amp; &ldquo;<code>&gt;</code>&rdquo;) into their encoded equivalents (&ldquo;<code>&amp;lt;</code>&rdquo; &amp; &ldquo;<code>&amp;gt;</code>&rdquo;).</p>
<pre><code>// escape html entities in comments
function encode_code_in_comment($source) {
	$encoded = preg_replace_callback('/&lt;code&gt;(.*?)&lt;\/code&gt;/ims',
	create_function('$matches', '$matches[1] = preg_replace(array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "", $matches[1]); 
	return "&lt;code&gt;" . htmlentities($matches[1]) . "&lt;/"."code&gt;";'), $source);
	if ($encoded)
		return $encoded;
	else
		return $source;
}
add_filter('pre_comment_content', 'encode_code_in_comment');</code></pre>
<p>Once in place in your <code>functions.php</code> file, simply tell your commentators to wrap their code snippets in <code>&lt;code&gt;</code> tags. In other words, any content wrapped in <code>&lt;code&gt;</code> tags will be encoded automatically. Plus, in order to prevent unwanted <code>&lt;br</code>&nbsp;<code>/&gt;</code> tags, this function also automatically removes line breaks after the opening <code>&lt;code&gt;</code> tag and before the closing <code>&lt;code&gt;</code> tag.</p>
<h3>Custom comments display callback function</h3>
<p>When designing your theme&rsquo;s <code>comments.php</code> file, you can use either WordPress&rsquo; default code or create your own for full control over your comments display. If you&rsquo;re rolling your own, it is often easiest to grab a solid comments-display template and customize it to suit your needs. After many iterations and much refining, here is the comments callback function that I usually begin with:</p>
<pre><code>// custom comments callback function
function custom_comments_callback($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment; ?&gt;

	&lt;li &lt;?php comment_class(); ?&gt; id="comment-&lt;?php comment_ID(); ?&gt;"&gt;
		&lt;div class="comment-wrap"&gt;
			&lt;?php echo get_avatar(get_comment_author_email(), $size = '50', $default = bloginfo('stylesheet_directory').'/images/gravatar.png'); ?&gt;

			&lt;div class="comment-intro"&gt;
            			&lt;?php printf(__('%s'), get_comment_author_link()); ?&gt; &amp;ndash; &lt;a class="comment-permalink" href="&lt;?php echo htmlspecialchars(get_comment_link($comment-&gt;comment_ID)); ?&gt;"&gt;&lt;?php comment_date('F j, Y'); ?&gt; @ &lt;?php comment_time(); ?&gt;&lt;/a&gt;&lt;?php edit_comment_link('Edit', ' &amp;ndash; ', ''); ?&gt;
			&lt;/div&gt;
			&lt;?php if ($comment-&gt;comment_approved == '0') : ?&gt;

			&lt;p class="comment-moderation"&gt;&lt;?php _e('Your comment is awaiting moderation.'); ?&gt;&lt;/p&gt;
			&lt;?php endif; ?&gt;

			&lt;div class="comment-text"&gt;&lt;?php comment_text(); ?&gt;&lt;/div&gt;

			&lt;div class="reply" id="comment-reply-&lt;?php comment_ID(); ?&gt;"&gt;
				&lt;?php comment_reply_link(array_merge($args, array('reply_text'=&gt;'Reply', 'login_text'=&gt;'Log in to Reply', 'add_below'=&gt;'comment-reply', 'depth'=&gt;$depth, 'max_depth'=&gt;$args['max_depth']))); ?&gt; 

			&lt;/div&gt;
		&lt;/div&gt;

&lt;?php } // WP adds the closing &lt;/li&gt;</code></pre>
<p>There&rsquo;s a lot going on here, so let&rsquo;s highlight the important stuff:</p>
<ul>
<li><strong>Do not</strong> add the closing <code>&lt;/li&gt;</code> element &ndash; <a href="http://digwp.com/2010/02/custom-comments-html-output/" title="Custom Comments HTML Output">WordPress does this for you</a>.</li>
<li>This function calls for a default gravatar in your theme&rsquo;s &ldquo;<code>images</code>&rdquo; directory. Either ensure you&rsquo;ve got the required image in place or edit the code to reflect your site&rsquo;s reality.</li>
<li>Once this function is included in your <code>functions.php</code> file, you can display it by using the following comments loop in your <code>comments.php</code> file:</li>
</ul>
<pre><code>&lt;?php if (have_comments()) : ?&gt;
&lt;ol class="commentlist"&gt;
	&lt;?php wp_list_comments('type=comment&amp;style=ol&amp;callback=custom_comments_callback'); ?&gt;
&lt;/ol&gt;
&lt;?php else : ?&gt;</code></pre>
<p>Notice the third parameter for the <code>wp_list_comments</code> template tag? that&rsquo;s what makes it go. Also important is the &ldquo;<code>style=ol</code>&rdquo; parameter, which tells WordPress that we are using an ordered list for comments and that it should automatically close the markup with a <code>&lt;/li&gt;</code> element.</p>
<h3>Putting it all together..</h3>
<p>As promised, here is the full-meal deal &ndash; the entire collection neatly organized into a single chunk of code:</p>
<pre><code>&lt;?php // custom functions.php template @ digwp.com

// add custom post content
function add_post_content($content) {
	if(!is_feed() &amp;&amp; !is_home()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_content', 'add_post_content');


// add custom feed content
function add_feed_content($content) {
	if(is_feed()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_excerpt_rss', 'add_feed_content');
add_filter('the_content', 'add_feed_content');


/* add custom content to feeds and posts
function add_custom_content($content) {
	if(!is_home()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_excerpt_rss', 'add_custom_content');
add_filter('the_content', 'add_custom_content'); */


// remove version info from head and feeds
function complete_version_removal() {
	return '';
}
add_filter('the_generator', 'complete_version_removal');


// customize admin footer text
function custom_admin_footer() {
	echo '&lt;a href="http://monzilla.biz/"&gt;Website Design by Monzilla Media&lt;/a&gt;';
} 
add_filter('admin_footer_text', 'custom_admin_footer');


// enable html markup in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');


// delay feed update
function publish_later_on_feed($where) {
	global $wpdb;

	if (is_feed()) {
		// timestamp in WP-format
		$now = gmdate('Y-m-d H:i:s');

		// value for wait; + device
		$wait = '5'; // integer

		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
		$device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

		// add SQL-sytax to default $where
		$where .= " AND TIMESTAMPDIFF($device, $wpdb-&gt;posts.post_date_gmt, '$now') &gt; $wait ";
	}
	return $where;
}
add_filter('posts_where', 'publish_later_on_feed');


// admin link for all settings
function all_settings_link() {
	add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
add_action('admin_menu', 'all_settings_link');


// remove nofollow from comments
function xwp_dofollow($str) {
	$str = preg_replace(
		'~&lt;a ([^&gt;]*)\s*(["|\']{1}\w*)\s*nofollow([^&gt;]*)&gt;~U',
		'&lt;a ${1}${2}${3}&gt;', $str);
	return str_replace(array(' rel=""', " rel=''"), '', $str);
}
remove_filter('pre_comment_content',     'wp_rel_nofollow');
add_filter   ('get_comment_author_link', 'xwp_dofollow');
add_filter   ('post_comments_link',      'xwp_dofollow');
add_filter   ('comment_reply_link',      'xwp_dofollow');
add_filter   ('comment_text',            'xwp_dofollow');


// count words in posts
function word_count() {
	global $post;
	echo str_word_count($post-&gt;post_content);
}


// spam &amp; delete links for all versions of wordpress
function delete_comment_link($id) {
	if (current_user_can('edit_post')) {
		echo '| &lt;a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&amp;c='.$id.'"&gt;del&lt;/a&gt; ';
		echo '| &lt;a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&amp;dt=spam&amp;c='.$id.'"&gt;spam&lt;/a&gt;';
	}
}


/* disable all feeds
function fb_disable_feed() {
	wp_die(__('&lt;h1&gt;Feed not available, please visit our &lt;a href="'.get_bloginfo('url').'"&gt;Home Page&lt;/a&gt;!&lt;/h1&gt;'));
}
add_action('do_feed',      'fb_disable_feed', 1);
add_action('do_feed_rdf',  'fb_disable_feed', 1);
add_action('do_feed_rss',  'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1); */


// customize default gravatars
function custom_gravatars($avatar_defaults) {

	// change the default gravatar
	$customGravatar1 = get_bloginfo('template_directory').'/images/gravatar-01.png';
	$avatar_defaults[$customGravatar1] = 'Default';

	// add a custom user gravatar
	$customGravatar2 = get_bloginfo('template_directory').'/images/gravatar-02.png';
	$avatar_defaults[$customGravatar2] = 'Custom Gravatar';

	// add another custom gravatar
	$customGravatar3 = get_bloginfo('template_directory').'/images/gravatar-03.png';
	$avatar_defaults[$customGravatar3] = 'Custom gravatar';

	return $avatar_defaults;
}
add_filter('avatar_defaults', 'custom_gravatars');


// disable auto formatting in posts
function my_formatter($content) {
	$new_content = '';
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

	foreach ($pieces as $piece) {
		if (preg_match($pattern_contents, $piece, $matches)) {
			$new_content .= $matches[1];
		} else {
			$new_content .= wptexturize(wpautop($piece));
		}
	}

	return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'my_formatter', 99);


// escape html entities in comments
function encode_code_in_comment($source) {
	$encoded = preg_replace_callback('/&lt;code&gt;(.*?)&lt;\/code&gt;/ims',
	create_function('$matches', '$matches[1] = preg_replace(array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "", $matches[1]); 
	return "&lt;code&gt;" . htmlentities($matches[1]) . "&lt;/"."code&gt;";'), $source);
	if ($encoded)
		return $encoded;
	else
		return $source;
}
add_filter('pre_comment_content', 'encode_code_in_comment');


// custom comments callback function
function custom_comments_callback($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment; ?&gt;

	&lt;li &lt;?php comment_class(); ?&gt; id="comment-&lt;?php comment_ID(); ?&gt;"&gt;
		&lt;div class="comment-wrap"&gt;
			&lt;?php echo get_avatar(get_comment_author_email(), $size = '50', $default = bloginfo('stylesheet_directory').'/images/gravatar.png'); ?&gt;

			&lt;div class="comment-intro"&gt;
            			&lt;?php printf(__('%s'), get_comment_author_link()); ?&gt; &amp;ndash; &lt;a class="comment-permalink" href="&lt;?php echo htmlspecialchars(get_comment_link($comment-&gt;comment_ID)); ?&gt;"&gt;&lt;?php comment_date('F j, Y'); ?&gt; @ &lt;?php comment_time(); ?&gt;&lt;/a&gt;&lt;?php edit_comment_link('Edit', ' &amp;ndash; ', ''); ?&gt;
			&lt;/div&gt;
			&lt;?php if ($comment-&gt;comment_approved == '0') : ?&gt;

			&lt;p class="comment-moderation"&gt;&lt;?php _e('Your comment is awaiting moderation.'); ?&gt;&lt;/p&gt;
			&lt;?php endif; ?&gt;

			&lt;div class="comment-text"&gt;&lt;?php comment_text(); ?&gt;&lt;/div&gt;

			&lt;div class="reply" id="comment-reply-&lt;?php comment_ID(); ?&gt;"&gt;
				&lt;?php comment_reply_link(array_merge($args, array('reply_text'=&gt;'Reply', 'login_text'=&gt;'Log in to Reply', 'add_below'=&gt;'comment-reply', 'depth'=&gt;$depth, 'max_depth'=&gt;$args['max_depth']))); ?&gt; 

			&lt;/div&gt;
		&lt;/div&gt;

&lt;?php } // WP adds the closing &lt;/li&gt;

?&gt;</code></pre>
<h3 id="functions-download">Download the custom functions.php template file</h3>
<p>If you prefer, you can download this code in a ready-to-go <code>functions.php</code> file in zipped format:</p>
<h4><a href="http://digwp.com/plugins/custom-functions-template-2.zip">Download zipped functions.php Template File</a></h4>
<h3>Also..</h3>
<p>If this post is useful to <acronym title="Digging into WordPress">DiW</acronym> readers, I’ll be writing up yet another article (part 3!) with even more useful custom functions. If that happens, the third set of functions will include some slightly more advanced techniques. <a href="http://feeds2.feedburner.com/DiggingIntoWordpress" title="Grab the Feed!">Stay tuned</a>!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/">Permalink</a> | <a href="http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/#comments">17 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/&title=WordPress Custom functions.php Template, Part 2">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>WordPress functions.php Template with 15 Essential Custom Functions</title>
		<link>http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/</link>
		<comments>http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 06:25:58 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1699</guid>
		<description><![CDATA[When designing WordPress themes, I always add a common set of custom functions to the theme&#8217;s functions.php file. This speeds up development time because I don&#8217;t have to hunt for and individually copy the same slew of functions for every theme. I just drop in a copy of my functions.php template and build up from [...]]]></description>
			<content:encoded><![CDATA[<p>When designing WordPress themes, I always add <strong>a common set of custom functions</strong> to the theme&rsquo;s <code>functions.php</code> file. This speeds up development time because I don&rsquo;t have to hunt for and individually copy the same slew of functions for <em>every</em> theme. I just drop in a copy of my <strong>functions.php template</strong> and build up from there. This takes care of all those little things that always need to be done:</p>
<ul>
<li>Include jQuery</li>
<li>Enable threaded comments</li>
<li>Add feed links to the header</li>
<li>Disable unused widget areas</li>
<li>Adding Google Analytics to the footer</li>
<li>Stop the &ldquo;Read More&rdquo; link from jumping to the middle of the next page&nbsp;;)</li>
</ul>
<p>One of the things that I like about these functions is that they&rsquo;re all so concise, simple, and effective. The <code>functions.php</code> template file currently contains 15 different functions and is a continual work in progress. Not everyone is going to need or use everything in the file, but the idea is to modify this template into something that works for you. It&rsquo;s a starting point with some really useful functions.</p>
<p><span id="more-1699"></span></p>
<p>In this <acronym title="Digging into WordPress">DiW</acronym> article, we first provide an explanation of each of the 15 functions and then bring them all together into the working <code>functions.php</code> template. Just copy and paste the template code at the end of this article or <a href="#functions-download" title="Download the zipped template file">grab a copy of the zipped <code>functions.php</code> file</a> and enjoy a custom collection of functions that will help you optimize your development process while enhancing WordPress with essential functionality.</p>
<h3>Add feed links to header</h3>
<p>Since version 2.8, WordPress can add all relevant feed links (main, comments, categories, et al) to your <code>&lt;head&gt;</code> area. It doesn&rsquo;t happen by default, however, because you have to add the following snippet to make it work:</p>
<pre><code>// add feed links to header
if (function_exists('automatic_feed_links')) {
	automatic_feed_links();
} else {
	return;
}</code></pre>
<p>This will check to see if you&rsquo;re using a version of WordPress that is compatible, and then enable the automatic feed links. A couple of notes: first, this method assumes that you are not manually including any feed links in your <code>&lt;head&gt;</code>. Also, I read a <a href="http://core.trac.wordpress.org/ticket/12364" title="Deprecate automatic_feed_links() in favor of add_theme_support()">recent Trac ticket</a> that looked like this functionality was being integrated with <code>add_theme_support</code>, so keep your eyes open for that.</p>
<h3>Automatic jQuery inclusion</h3>
<p>We&rsquo;ve discussed <a href="http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/" title="Including jQuery in WordPress (The Right Way)">how to include jQuery the right way</a> by placing a little snippet in your document head, but here is a way to do it from your theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>// smart jquery inclusion
if (!is_admin()) {
	wp_deregister_script('jquery');
	wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false);
	wp_enqueue_script('jquery');
}</code></pre>
<p>This code ensures that only one copy of jQuery is included, and calls it from Google&rsquo;s servers to save bandwidth and take advantage of any primed caches that happen to be visiting. Note that this function needs to be located <em>before</em> the threaded-comments function in order for it to work.</p>
<h3>Enable threaded comments</h3>
<p>As we explain in <a href="http://digwp.com/book/" title="Get the Book!">the book</a>, enabling threaded comments requires adding a snippet of code into your <code>&lt;head&gt;</code> area just before the <code>wp_head</code> tag. After a little experimenting, I discovered that you can include this snippet from the <code>functions.php</code> file:</p>
<pre><code>// enable threaded comments
function enable_threaded_comments(){
	if (!is_admin()) {
		if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))
			wp_enqueue_script('comment-reply');
		}
}
add_action('get_header', 'enable_threaded_comments');</code></pre>
<p>This helps keep your document <code>&lt;head&gt;</code> a little cleaner. Note that this function needs to be located <em>after</em> the jQuery-inclusion function in order for it to work.</p>
<p>Thanks to <a href="http://soupgiant.com/">Peter Wilson</a> for this <a href="http://bigredtin.com/wordpress/including-wordpress-comment-reply-js/" title="Including WordPress' comment-reply.js (the right way)">awesome technique</a>!</p>
<h3>Remove unwanted crap from the head section</h3>
<p>As we&rsquo;ve <a href="http://digwp.com/2009/07/remove-wordpress-version-number/" title="How to Remove the WordPress Version Number (The Right Way)">mentioned before</a>, WordPress spits out a <em>ton</em> of crap in the document <code>&lt;head&gt;</code> &ndash; stuff like the version number and <acronym title="Windows Live Writer">WLW</acronym>, <acronym title="Really Simple Discovery">RSD</acronym>, and index links. To clean things up, we add this nice little snippet into the <code>functions.php</code> template:</p>
<pre><code>// remove junk from head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);</code></pre>
<h3>Add Google Analytics to the footer</h3>
<p>Another annoying task that has to be done for all of the sites I create is adding Google Analytics code to the <code>footer.php</code> file. Recently it occurred to me to just add the code to my <code>functions.php</code> and never worry about it again:</p>
<pre><code>// add google analytics to footer
function add_google_analytics() {
	echo '&lt;script src="http://www.google-analytics.com/ga.js" type="text/javascript"&gt;&lt;/script&gt;';
	echo '&lt;script type="text/javascript"&gt;';
	echo 'var pageTracker = _gat._getTracker("UA-XXXXX-X");';
	echo 'pageTracker._trackPageview();';
	echo '&lt;/script&gt;';
}
add_action('wp_footer', 'add_google_analytics');</code></pre>
<p>A couple of notes here: first, obviously you want to replace the &ldquo;<code>UA-123456-1</code>&rdquo; with your actual <acronym title="Google Analytics">GA</acronym> code. Second, you may want to check out the <a href="http://perishablepress.com/press/2010/01/24/3-ways-track-google-analytics/" title="3 Ways to Track Web Pages with Google Analytics">three currently available Analytics options</a> and modify the code accordingly. Currently, this function is using the newer &ldquo;<code>ga.js</code>&rdquo; tracking code, but that is easily changed to either of the other methods.</p>
<h3>Custom excerpt length</h3>
<p>Instead of using the default 55-word limit, this function enables you to specify any length for your excerpts.</p>
<pre><code>// custom excerpt length
function custom_excerpt_length($length) {
	return 20;
}
add_filter('excerpt_length', 'custom_excerpt_length');</code></pre>
<p>Just set your preferred number of words by editing the &ldquo;<code>20</code>&rdquo; to whatever you wish.</p>
<h3>Custom excerpt &ldquo;continue&rdquo; string</h3>
<p>Or whatever they call that funky bracketed ellipses thing &ldquo;<code>[...]</code>&rdquo; that is appended to your post excerpts by default. I like to remove the brackets, but with this <code>functions.php</code> snippet you can change it to anything:</p>
<pre><code>// custom excerpt ellipses for 2.9+
function custom_excerpt_more($more) {
	return '...';
}
add_filter('excerpt_more', 'custom_excerpt_more');

/* custom excerpt ellipses for 2.8-
function custom_excerpt_more($excerpt) {
	return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_trim_excerpt', 'custom_excerpt_more'); 
*/</code></pre>
<p>As you can see, there are two different versions of this code, depending on your version of WordPress. We like to stay current, so we commented out the older method but left it there in case you need it. For either version of this technique, just replace the &ldquo;<code>...</code>&rdquo; with &ldquo;pants on the ground&rdquo; or whatever happens to suit your needs.</p>
<h3>No &ldquo;more&rdquo; jumping for the &ldquo;read more&rdquo; link</h3>
<p>One of the weirdest things that WordPress does is &ldquo;jump&rdquo; the reader to the location of the &ldquo;<code>&lt;!--</code><code>more--&gt;</code>&rdquo; tag on the single-post-view when the &ldquo;read more&rdquo; link is clicked. It&rsquo;s just awkward &#8212; if the jump was on the <em>same</em> page, it would make sense, but to load a new page and then take the reader halfway down without explaining anything is just wrong. In any case, here is a nice little function that will stop the jumping once and for all:</p>
<pre><code>// no more jumping for read more link
function no_more_jumping($post) {
	return '&lt;a href="'.get_permalink($post-&gt;ID).'" class="read-more"&gt;'.'Continue Reading'.'&lt;/a&gt;';
}
add_filter('excerpt_more', 'no_more_jumping');
add_filter('the_content_more_link', 'remove_more_jump_link');</code></pre>
<p>Nothing else needs to be done for this to work &ndash; just plug it in and enjoy your new &ldquo;jumpless&rdquo; functionality. Note that this is also a convenient place to customize the &ldquo;read more&rdquo; link with whatever attributes or custom text you wish.</p>
<h3>Add a favicon to your blog</h3>
<p>You just <em>gotsta</em> have a favicon for your blog, and this code makes it super easy to do. Just create your image and upload to site&rsquo;s root directory. The following code in your <code>functions.php</code> file makes it so by adding the required line to your <code>&lt;head&gt;</code> area:</p>
<pre><code>// add a favicon to your 
function blog_favicon() {
	echo '&lt;link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'/favicon.ico" /&gt;';
}
add_action('wp_head', 'blog_favicon');</code></pre>
<p>Feel free to change the directory to whatever you desire. Also make sure that the <code>wp_head</code> is present within your theme&rsquo;s <code>header.php</code> file.</p>
<h3>Add a different favicon for your blog&rsquo;s Admin area</h3>
<p>While we&rsquo;re here, let&rsquo;s add a unique favicon to our Admin pages, so that they are easier to recognize when bookmarked or working with tabs. Just create a favicon and upload to your theme&rsquo;s <code>/images/</code> directory. This code takes care of the rest:</p>
<pre><code>// add a favicon for your admin
function admin_favicon() {
	echo '&lt;link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('stylesheet_directory').'/images/favicon.png" /&gt;';
}
add_action('admin_head', 'admin_favicon');</code></pre>
<p>As before, feel free to change the directory to whatever you desire. It might be best to keep your admin favicon in a separate directory than your blog favicon. Just sayin&rsquo;.</p>
<h3>Custom Admin Login logo</h3>
<p>You know that snazzy blue WordPress logo that is branding your various login pages? Yeh, you can change that to whatever you want. Just create your custom login image, name it &ldquo;<code>custom-login-logo.png</code>&rdquo;, and upload it to your theme&rsquo;s <code>/images/</code> directory. This code will take care of the rest:</p>
<pre><code>// custom admin login logo
function custom_login_logo() {
	echo '&lt;style type="text/css"&gt;
	h1 a { background-image: url('.get_bloginfo('template_directory').'/images/custom-login-logo.png) !important; }
	&lt;/style&gt;';
}
add_action('login_head', 'custom_login_logo');</code></pre>
<p>The key here is to make sure that the path and image names match that of your setup. Also, when creating your image, you may want to keep in mind the properties of the original: 30px length, 31px height, transparent <acronym title="Graphic Interchange Format">GIF</acronym> format, and header background color of #464646 (for the image matte).</p>
<h3>Disable unused widget areas</h3>
<p><a href="http://justintadlock.com/archives/2009/03/06/disable-widget-areas-without-touching-theme-templates" title="Disable widget areas (sidebars) without touching theme templates">Justin Tadlock</a> shares this handy function for removing unwanted widget areas from our theme &ndash; a <em>must</em> for customizing  existing themes:</p>
<pre><code>// disable all widget areas
function disable_all_widgets($sidebars_widgets) {
	//if (is_home())
		$sidebars_widgets = array(false);
	return $sidebars_widgets;
}
add_filter('sidebars_widgets', 'disable_all_widgets');</code></pre>
<p>This code is plug-&amp;-play &ndash; no other modifications need to be made. Note: if you only want to disable widgets on your Home page, then remove the two comment slashes (&ldquo;<code>//</code>&rdquo;) from the third line.</p>
<h3>Kill the WordPress update nag</h3>
<p>This is one of my favorites, but I know it&rsquo;s not for everyone. In any case, you know that &ldquo;Please update now..&rdquo; message that appears on every page in the WordPress Admin when new versions are available? This sweet little function kills it dead (or disables it, actually):</p>
<pre><code>// kill the admin nag
if (!current_user_can('edit_users')) {
	add_action('init', create_function('$a', "remove_action('init', 'wp_version_check');"), 2);
	add_filter('pre_option_update_core', create_function('$a', "return null;"));
}</code></pre>
<p>Feel free to comment this one out or remove it if you rely on the Admin nag to keep you informed of changes.</p>
<h3>Include category ID in body_class and post_class</h3>
<p>By default, WordPress <code>body_class</code> and <code>post_class</code> do not include the ID of the category of the current post. This custom function changes all that:</p>
<pre><code>// category id in body and post class
function category_id_class($classes) {
	global $post;
	foreach((get_the_category($post-&gt;ID)) as $category)
		$classes [] = 'cat-' . $category-&gt;cat_ID . '-id';
		return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');</code></pre>
<p>Even if you aren&rsquo;t using it, it&rsquo;s a nice function to have around, which is why it&rsquo;s included here for this custom <code>functions.php</code> template of essential functions. Keywords in the house because we can.</p>
<h3>Get the first category ID</h3>
<p>Another useful function when working with different categories is the ability to get the first category ID of the current post. This function makes it happen:</p>
<pre><code>// get the first category id
function get_first_category_ID() {
	$category = get_the_category();
	return $category[0]-&gt;cat_ID;
}</code></pre>
<p>Strictly plug-&amp;-play: just use <code>&lt;?php get_first_category_ID(); ?&gt;</code> in your theme template file to access the data.</p>
<h3>Putting it all together..</h3>
<p>As promised, here is the full-meal deal &ndash; the entire collection neatly organized into a single chunk of code:</p>
<pre><code>&lt;?php // custom functions.php template @ digwp.com

// add feed links to header
if (function_exists('automatic_feed_links')) {
	automatic_feed_links();
} else {
	return;
}


// smart jquery inclusion
if (!is_admin()) {
	wp_deregister_script('jquery');
	wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.3.2');
	wp_enqueue_script('jquery');
}


// enable threaded comments
function enable_threaded_comments(){
	if (!is_admin()) {
		if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))
			wp_enqueue_script('comment-reply');
		}
}
add_action('get_header', 'enable_threaded_comments');


// remove junk from head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);


// add google analytics to footer
function add_google_analytics() {
	echo '&lt;script src="http://www.google-analytics.com/ga.js" type="text/javascript"&gt;&lt;/script&gt;';
	echo '&lt;script type="text/javascript"&gt;';
	echo 'var pageTracker = _gat._getTracker("UA-XXXXX-X");';
	echo 'pageTracker._trackPageview();';
	echo '&lt;/script&gt;';
}
add_action('wp_footer', 'add_google_analytics');


// custom excerpt length
function custom_excerpt_length($length) {
	return 20;
}
add_filter('excerpt_length', 'custom_excerpt_length');


// custom excerpt ellipses for 2.9+
function custom_excerpt_more($more) {
	return '...';
}
add_filter('excerpt_more', 'custom_excerpt_more');

/* custom excerpt ellipses for 2.8-
function custom_excerpt_more($excerpt) {
	return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_trim_excerpt', 'custom_excerpt_more'); 
*/


// no more jumping for read more link
function no_more_jumping($post) {
	return '&lt;a href="'.get_permalink($post-&gt;ID).'" class="read-more"&gt;'.'Continue Reading'.'&lt;/a&gt;';
}
add_filter('excerpt_more', 'no_more_jumping');


// add a favicon to your 
function blog_favicon() {
	echo '&lt;link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'/favicon.ico" /&gt;';
}
add_action('wp_head', 'blog_favicon');


// add a favicon for your admin
function admin_favicon() {
	echo '&lt;link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('stylesheet_directory').'/images/favicon.png" /&gt;';
}
add_action('admin_head', 'admin_favicon');


// custom admin login logo
function custom_login_logo() {
	echo '&lt;style type="text/css"&gt;
	h1 a { background-image: url('.get_bloginfo('template_directory').'/images/custom-login-logo.png) !important; }
	&lt;/style&gt;';
}
add_action('login_head', 'custom_login_logo');


// disable all widget areas
function disable_all_widgets($sidebars_widgets) {
	//if (is_home())
		$sidebars_widgets = array(false);
	return $sidebars_widgets;
}
add_filter('sidebars_widgets', 'disable_all_widgets');


// kill the admin nag
if (!current_user_can('edit_users')) {
	add_action('init', create_function('$a', "remove_action('init', 'wp_version_check');"), 2);
	add_filter('pre_option_update_core', create_function('$a', "return null;"));
}


// category id in body and post class
function category_id_class($classes) {
	global $post;
	foreach((get_the_category($post-&gt;ID)) as $category)
		$classes [] = 'cat-' . $category-&gt;cat_ID . '-id';
		return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');


// get the first category id
function get_first_category_ID() {
	$category = get_the_category();
	return $category[0]-&gt;cat_ID;
}

?&gt;</code></pre>
<h3 id="functions-download">Download the custom functions.php template file</h3>
<p>If you prefer, you can download this code in a ready-to-go <code>functions.php</code> file in zipped format:</p>
<h4><a href="http://digwp.com/plugins/custom-functions-template.zip">Download zipped functions.php Template File</a></h4>
<h3>Also..</h3>
<p>If this post is useful to <acronym title="Digging into WordPress">DiW</acronym> readers, I&rsquo;ll be writing up another article (part 2) with even more useful custom functions. If that happens, the second set of functions will include some slightly more advanced techniques as opposed to these &ldquo;must-have&rdquo; template functions. <a href="http://feeds2.feedburner.com/DiggingIntoWordpress" title="Grab the Feed!">Stay tuned</a>! <strong>Update:</strong> <a href="http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/" title="WordPress Custom functions.php Template, Part 2">Custom functions.php Part 2 is here</a>!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/">Permalink</a> | <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/#comments">80 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/&title=WordPress functions.php Template with 15 Essential Custom Functions">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/feed/</wfw:commentRss>
		<slash:comments>80</slash:comments>
		</item>
		<item>
		<title>Add Classes to post_class</title>
		<link>http://digwp.com/2010/03/add-classes-to-post_class/</link>
		<comments>http://digwp.com/2010/03/add-classes-to-post_class/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 21:04:45 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1567</guid>
		<description><![CDATA[The post_class() function in WordPress is pretty darn useful. It is used like this, in most templates, in a wrapping div of all the content you are outputting: &#60;div &#60;?php post_class() ?&#62; id="post-&#60;?php the_ID(); ?&#62;"&#62; &#60;!-- Post stuff --&#62; &#60;/div&#62; I was in a circumstance where I wanted to add an additional class to what [...]]]></description>
			<content:encoded><![CDATA[<p>The post_class() function in WordPress is pretty darn useful. It is used like this, in most templates, in a wrapping div of all the content you are outputting:</p>
<pre><code>&lt;div &lt;?php post_class() ?&gt; id="post-&lt;?php the_ID(); ?&gt;"&gt;
   &lt;!-- Post stuff --&gt;
&lt;/div&gt;</code></pre>
<p>I was in a circumstance where I wanted to add an additional class to what that was outputting. My thought process went like this:</p>
<ol>
<li>Arg. I guess I&#8217;m going to have to write a function to filter the output of that function. Let&#8217;s begin the research.</li>
<li>Wait. I bet that function has an alternate that returns a string rather than echos it. I&#8217;ll just use that, and echo it out along with my own custom class.</li>
<li>Double wait. I bet those smart WordPress folks have thought of this&#8230;</li>
</ol>
<p><span id="more-1567"></span></p>
<h3>1. Filtering</h3>
<p>This kind of thing is generally beyond my comfort zone, but you&#8217;d basically write your own little function which takes in what the output would have been, add you own stuff to it, then return the new value.</p>
<p>Then call the new function with a filter in your functions.php file:</p>
<pre><code>add_filter('post_class','add_my_stuff');</code></pre>
<h3>2. Output exiting classes, then add yours</h3>
<p>Like most functions that echo stuff, there is a version that doesn&#8217;t echo stuff, in which &#8220;get_&#8221; prefaces the function name. I didn&#8217;t even have to look it up I just knew there would be. Since it&#8217;s a list, this function returns an array, so to output them, you&#8217;ll need to loop through the array:</p>
<pre><code>&lt;div class="&lt;?php $allClasses = get_post_class(); foreach ($allClasses as $class) { echo $class . " "; } ?&gt; group" id="post-&lt;?php the_ID(); ?&gt;"&gt;</code></pre>
<p>The cool part here is that is doesn&#8217;t add &#8220;class=&#8221; in the output, you can do that yourself, meaning that I can add my own classes after the output is finished.</p>
<h3>3. Built in&#8230;</h3>
<p>Of course, as it turns out, this is far easier than #2 made it out to be. To add additional classes, just pass them as a parameter!</p>
<pre><code>&lt;?php post_class('special'); ?&gt;</code></pre>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/add-classes-to-post_class/">Permalink</a> | <a href="http://digwp.com/2010/03/add-classes-to-post_class/#comments">2 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/add-classes-to-post_class/&title=Add Classes to post_class">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/classes/" rel="tag">classes</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/add-classes-to-post_class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Digging Into WordPress v2.0 + Print is Back! (Oh, and a fresh new design!)</title>
		<link>http://digwp.com/2010/03/digwpv2/</link>
		<comments>http://digwp.com/2010/03/digwpv2/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 13:06:24 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Site News]]></category>
		<category><![CDATA[Upgrade]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1526</guid>
		<description><![CDATA[Version 2.0 is here! If you have already purchased the book, you have already gotten an email with a link to download the 2.0 version of the book. If you have been waiting for the print version to come back in stock, the time is now! We sold out of the print version the first [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://digwp.com/book/" style="padding:0; border:0;"><img src="http://css-tricks.com/wp-content/csstricks-uploads/v2250promo.png" width="250" height="250" alt="" style="float: left; margin: 0 10px 2px 0;" /></a> Version 2.0 is here! If you have already purchased the book, you have already gotten an email with a link to download the 2.0 version of the book. If you have been waiting for the print version to come back in stock, the time is now! </p>
<p>We sold out of the print version the first round in a matter of weeks. Right about that time, WordPress 2.9 was coming out, so instead of just reprinting more we decided to update the book and print new copies with that fresh information. That is exactly what we have done. The all-new Chapter 11 of the book deals with new stuff in WordPress 2.9 (and how to use the new features). That chapter will also be the home for future version-specific updates to WordPress. </p>
<p>Read on to find out more about the book. Oh and by the way, <em>we&#8217;re sporting a fresh new design here on the site</em>. What do you think?</p>
<p><span id="more-1526"></span></p>
<p>There is also brand-new Chapter 10 called &#8220;Bonus Tricks!&#8221; which deals with some cool new tricks for your themes. This chapter is also where we <strong>introduce the new themes that now come bundled with the book</strong>. That&#8217;s right folks, the book now comes bundled with two major new themes, as well as some child themes for those, and a couple of other bonus themes. These themes are book-only, meaning that the only way to get them is through the book bundle, which comes with either book buying option.</p>
<p>The book is some 30+ pages longer, sporting a shinier tougher cover, thicker binding coil, and updated and improved content throughout, the price point is going to remain the same for both the PDF and Print bundle. It&#8217;s costing us a good bit more to produce, but we upped the quantity we ordered a bit to cover some of that. Still got the family working hard!</p>
<h3>Bundled Themes</h3>
<p>The best way to illustrate and explain something is often just to give someone the finished product and let them explore it. There is lots of code in the book, but it&#8217;s all removed from the context of a real design. Now you&#8217;ll get some real themes along with the book so you can see how that code is used in an actual theme. The themes do a particularly good job illustrating two big topics:</p>
<ul>
<li><strong>Theme Options Panel</strong> &#8211; Both themes have options panels for setting various theme-specific options. They are built in a &#8220;framework&#8221; style, so that adding your own or adjusting what options are there is pretty easy.</li>
<li><strong>Child Themes</strong> &#8211; Both themes come with a child theme which restyles the theme without affecting any of how it works. If you&#8217;ve always wondered how that works, you can see it with these themes.</li>
</ul>
<p><img src="http://css-tricks.com/wp-content/csstricks-uploads/bundledthemes.jpg" width="570" height="480" alt="" title="" /></p>
<h4>Plastique</h4>
<p>See theme options shine here as there is <strong>a ton</strong> of options to control your theme. Everything from how it is laid out (columns, positions) to what types of things you wish to include, to adding in markup into individual sections. <a href="http://themeclubhouse.digwp.com/index.php?wptheme=Plastique">Preview Theme</a></p>
<h4>Lines &#038; Boxes</h4>
<p>Based on the look of a wireframe, Lines &#038; Boxes could be used as-is for a minimalist look, or used as a starting point for a more fleshed out graphical theme. Some theme options including overriding the header of the site, and options on if you want the main navigation to be a category list or a page list. <a href="http://themeclubhouse.digwp.com/index.php?wptheme=Lines%20and%20Boxes">Preview Theme</a></p>
<h4>All AJAX</h4>
<p>&#8220;All Ajax&#8221;, also a bundled theme, is based off Lines &#038; Boxes but is not technically a child theme. The idea is that every internal link on the site loads without page refresh. <a href="http://themeplayground.digwp.com/index.php?wptheme=All%20AJAX">Preview Theme</a></p>
<h3>Get it</h3>
<p>Even with all the new themes and 30+ new pages, the price point for the book and PDF stay the same. $27 for the PDF and $67 + S&#038;H for the Book/PDF Combo. If you buy the print book, remember that automatically comes with the PDF which now comes as a bundle with the themes, so you don&#8217;t miss out on that action.</p>
<p><strong>What happens if you bought the PDF while the book was sold out and now want the print copy?</strong> That would be anytime between January 18th and February 28th. If that describes your situation, just forward a copy of your receipt to sales@digwp.com and ask us for a discount code. We&#8217;ll send you one you can use on the print copy good for the value of what you paid for the PDF.</p>
<p><a href="http://digwp.com/book/" class="button">Go get it!</a></p>
<h3>Regarding Shipping</h3>
<p>Books are basically being assembled at the time of this writing. It is likely that they&#8217;ll be boxed and labeled to ship to you folks a week from today. So if you order today, just note that you&#8217;ll probably get them in about 10-12 days. Later orders will arrive in typically more like 4-5 days. International orders take more time.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/digwpv2/">Permalink</a> | <a href="http://digwp.com/2010/03/digwpv2/#comments">26 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/digwpv2/&title=Digging Into WordPress v2.0 + Print is Back! (Oh, and a fresh new design!)">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/book/" rel="tag">book</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/digwpv2/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Custom Comments HTML Output</title>
		<link>http://digwp.com/2010/02/custom-comments-html-output/</link>
		<comments>http://digwp.com/2010/02/custom-comments-html-output/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 20:04:01 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1469</guid>
		<description><![CDATA[Displaying all the comments on a Post is incredibly easy. In your single.php file you probably have a line like this: &#60;?php comments_template(); ?&#62; That line basically calls/includes your comments.php file. Within that, the line to output all comments is something really simple like this: &#60;ol class="commentlist"&#62; &#60;?php wp_list_comments(); ?&#62; &#60;/ol&#62; But that doesn&#8217;t leave [...]]]></description>
			<content:encoded><![CDATA[<p>Displaying all the comments on a Post is incredibly easy. In your single.php file you probably have a line like this:</p>
<pre><code>&lt;?php comments_template(); ?&gt;</code></pre>
<p>That line basically calls/includes your comments.php file. Within that, the line to output all comments is something really simple like this:</p>
<pre><code>&lt;ol class="commentlist"&gt;
   &lt;?php wp_list_comments(); ?&gt;
&lt;/ol&gt;</code></pre>
<p>But that doesn&#8217;t leave much by way of customizing the HTML that gets output, does it? Fortunately it&#8217;s fairly easy to specify your own formatting in a non-destructive non-core-altering way. Although personally, I&#8217;m having one little issue with it. Let&#8217;s take a look.</p>
<p><span id="more-1469"></span></p>
<h3>Why would you need this?</h3>
<p>This is what you get as the defacto standard comment output:</p>
<div class="image-wrap">
<img src="http://digwp.com/wp-content/blog-images/comment-output.jpg" width="590" height="420" alt="" title="" /><br />
This is from the new 2010 theme slated to come out with WordPress 3
</div>
<p>But what if you wanted something more like this?</p>
<div class="image-wrap">
<img src="http://digwp.com/wp-content/blog-images/redonecomment.png" width="529" height="234" alt="" title="" /><br />
From a new client site I&#8217;ve been working on
</div>
<p>The best way to get into that new skin is to get your hands on the HTML, as CSS alone isn&#8217;t quite going to get us there.</p>
<h3>Custom output through a callback function</h3>
<p>The trick is is that the wp_list_comments function accepts a parameter for a callback function. This function overrides what the output of each comment will be. Here is an example of that:</p>
<pre><code>&lt;ol class="commentlist"&gt;
    &lt;?php wp_list_comments('type=comment&amp;callback=format_comment'); ?&gt;
&lt;/ol&gt;</code></pre>
<p>The above code will only output &#8220;comments&#8221; (and not trackbacks or pingbacks) and will call a custom function &#8220;format_comment&#8221; for formatting the comment. This function needs to be built in your functions.php file, and better be present before you call this function otherwise you&#8217;ll throw an error.</p>
<p>The callback function is completely in charge of the comment formatting. It could be something completely whacky like this:</p>
<pre><code>&lt;?php
    function format_comment() {  ?&gt;
           &lt;li&gt;This is whack, yo.&lt;/li&gt;
   &lt;?php } 
?&gt;</code></pre>
<p>Which would return that ridiculous sentence for every single comment, instead of the actual comment. Of course you wouldn&#8217;t (probably) ever do that. What you probably want to do, is just adjust how the different standard comment-related data is output. To do that, first you pull in the comment globals, then you can use all the comment functions that return the stuff that you probably want:</p>
<ul>
<li>get_comment_link</li>
<li>get_comment_author</li>
<li>get_comment_date</li>
<li>get_comment_time</li>
<li>get_comment_text</li>
<li>etc.</li>
</ul>
<p>Here is a customized formatting function I recently used:</p>
<pre><code>&lt;?php

    function format_comment($comment, $args, $depth) {
    
       $GLOBALS['comment'] = $comment; ?&gt;
       
        &lt;li &lt;?php comment_class(); ?&gt; id="li-comment-&lt;?php comment_ID() ?&gt;"&gt;
                
            &lt;div class="comment-intro"&gt;
                &lt;em&gt;commented on&lt;/em&gt; 
                &lt;a class="comment-permalink" href="&lt;?php echo htmlspecialchars ( get_comment_link( $comment-&gt;comment_ID ) ) ?&gt;"&gt;&lt;?php printf(__('%1$s'), get_comment_date(), get_comment_time()) ?&gt;&lt;/a&gt;
                &lt;em&gt;by&lt;/em&gt; 
                &lt;?php printf(__('%s'), get_comment_author_link()) ?&gt;
            &lt;/div&gt;
            
            &lt;?php if ($comment-&gt;comment_approved == '0') : ?&gt;
                &lt;em&gt;&lt;php _e('Your comment is awaiting moderation.') ?&gt;&lt;/em&gt;&lt;br /&gt;
            &lt;?php endif; ?&gt;
            
            &lt;?php comment_text(); ?&gt;
            
            &lt;div class="reply"&gt;
                &lt;?php comment_reply_link(array_merge( $args, array('depth' =&gt; $depth, 'max_depth' =&gt; $args['max_depth']))) ?&gt;
            &lt;/div&gt;
        
&lt;?php } ?&gt;</code></pre>
<h3>When NOT to customize output</h3>
<p>Remember that CSS is quite the handyman at whipping things into shape. Let&#8217;s say your goal was to get rid of the gravatars that the default comment formatting outputs. Well that&#8217;s as simple as:</p>
<pre><code>.avatar { display: none; }</code></pre>
<p>And with more powerful tools like absolute positioning, you can take the default output and really do a ton of customization. There are some times though, when you need to alter the HTML to do it right, and that&#8217;s when all this is useful.</p>
<h3>My little problem</h3>
<p>My custom output works really well, save for one little problem. That is nested replies. The WORK, it&#8217;s just the output is invalid, as nested lists sit directly within the list above it instead of being wrapped in a list item like they should be. See:</p>
<p><img src="http://digwp.com/wp-content/blog-images/naughtyoutput.jpg" width="590" height="720" alt="" title="" /></p>
<p>I&#8217;m not quite sure how to fix that, although I imagine it can be done within the custom function somehow? If anyone knows, let me know.</p>
<h3>Update</h3>
<p>It was my mistake, although in my defense, the answer is a little weird. What you need to is <strong>OMIT</strong> the closing <code>&amp;lt;/li&amp;gt;</code> tag in the callback function. WordPress will add that automatically for you. </p>
<p>In other news, if you find your callback function breaks the &#8220;Reply&#8221; button functionality, take a look at the <code>add_below</code> parameter:</p>
<pre><code>&lt;?php comment_reply_link(array_merge( $args, array('reply_text' =&gt; 'Reply', 'add_below' =&gt; $add_below, 'depth' =&gt; $depth, 'max_depth' =&gt; $args['max_depth']))); ?&gt; </code></pre>
<p>That parameter takes a string, like &#8220;div-comment&#8221; for example, and then the reply links on each comment will be looking for the page element of &#8220;div-comment-XXXX&#8221; to jump the comment form up to (where XXXX is the ID of the comment). So your theme better have page elements with matching ID&#8217;s, or the reply link will &#8220;fail&#8221; and reload the page. I say &#8220;fail&#8221; in quotes because replying will still work, it just doesn&#8217;t do the cool jump-up technique which is the whole point of the <code>comment-reply.js</code> file that most themes load on single pages.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/02/custom-comments-html-output/">Permalink</a> | <a href="http://digwp.com/2010/02/custom-comments-html-output/#comments">14 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/02/custom-comments-html-output/&title=Custom Comments HTML Output">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/comments/" rel="tag">comments</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/02/custom-comments-html-output/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

