<?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/category/theme/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Learn how to take your WordPress skills to the next level.</description>
	<lastBuildDate>Wed, 01 Sep 2010 14:47:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The &#8220;Frameworks&#8221;&#160;Discussion</title>
		<link>http://digwp.com/2010/07/the-frameworks-discussion/</link>
		<comments>http://digwp.com/2010/07/the-frameworks-discussion/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 09:20:12 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[discussion]]></category>
		<category><![CDATA[frameworks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2340</guid>
		<description><![CDATA[I&#8217;ve never been a big fan of &#8220;theme frameworks.&#8221; I quite like hacking up WordPress myself and making it do the things I want it to do. I feel like most theme frameworks have a ton of custom functions for you to &#8220;help&#8221; in doing that kind of stuff. For example, adding a block of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve never been a big fan of &#8220;theme frameworks.&#8221; I quite like hacking up WordPress myself and making it do the things I want it to do. I feel like most theme frameworks have a ton of custom functions for you to &#8220;help&#8221; in doing that kind of stuff. For example, adding a block of text to the sidebar, adjusting the layout, or building a custom menu. </p>
<p><span id="more-2340"></span></p>
<p>So because frameworks have all these helper functions, they are targeted at people who don&#8217;t want to learn how to do all that stuff themselves, but still harness all that power. In other words, non-nerds. These helper functions are used by hand-altering theme files, which is inherently nerdy. So frameworks are for non-nerds, but the only people that know about them (and especially how to use them), are nerds.</p>
<p>Or am I full of crap?</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/07/the-frameworks-discussion/">Permalink</a> | <a href="http://digwp.com/2010/07/the-frameworks-discussion/#comments">66 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/07/the-frameworks-discussion/&title=The &#8220;Frameworks&#8221;&nbsp;Discussion">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a>, <a href="http://digwp.com/category/uncategorized/" title="View all posts in Uncategorized" rel="category tag">Uncategorized</a> | Tagged: <a href="http://digwp.com/tag/discussion/" rel="tag">discussion</a>, <a href="http://digwp.com/tag/frameworks/" rel="tag">frameworks</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/07/the-frameworks-discussion/feed/</wfw:commentRss>
		<slash:comments>66</slash:comments>
		</item>
		<item>
		<title>WordPress Custom functions.php Template, Part&#160;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>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></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&nbsp;2">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/design/" title="View all posts in Design" rel="category tag">Design</a>, <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <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></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&#160;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');</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>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></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&nbsp;Functions">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/design/" title="View all posts in Design" rel="category tag">Design</a>, <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <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></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>Custom Comments HTML&#160;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>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></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&nbsp;Output">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <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></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/02/custom-comments-html-output/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Which Template File does WordPress Use to Render Different&#160;Pages?</title>
		<link>http://digwp.com/2010/02/template-heirarchy-chart/</link>
		<comments>http://digwp.com/2010/02/template-heirarchy-chart/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 14:34:51 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1431</guid>
		<description><![CDATA[This page in the codex has a particularly interesting infographic that shows a flowchart of how WordPress chooses which template file it is going to use to render the page. For example, did you know if you have a published page with &#8220;contact&#8221; as the slug, it will look for and use page-contact.php automatically? Unfortunately [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://codex.wordpress.org/Template_Hierarchy">This page</a> in the codex has a particularly interesting infographic that shows a flowchart of how WordPress chooses which template file it is going to use to render the page. For example, did you know if you have a published page with &#8220;contact&#8221; as the slug, it will look for and use page-contact.php automatically?</p>
<p>Unfortunately this graphic wasn&#8217;t very pretty and for some reason has a giant &#8220;Page 1&#8243; text awkward sitting over it. We have an outdated version of this in the book, and since we are updating it right now, I thought I would take the opportunity to re-create this chart.</p>
<p><span id="more-1431"></span></p>
<p><a href="http://digwp.com/wp-content/blog-images/whichtemplate-large.png">CLICK FOR FULL SIZE VERSION</a><br />
<a href="http://digwp.com/wp-content/blog-images/whichtemplate-large.png"><img src="http://digwp.com/wp-content/blog-images/whichtemplate-small.png" width="590" height="472" alt="" title="" /></a></p>
<p>This will also be used in the <a href="http://digwp.com/book/">book</a>, which should be back available for order in around a week or so! Stay tuned!</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/02/template-heirarchy-chart/">Permalink</a> | <a href="http://digwp.com/2010/02/template-heirarchy-chart/#comments">12 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/02/template-heirarchy-chart/&title=Which Template File does WordPress Use to Render Different&nbsp;Pages?">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/02/template-heirarchy-chart/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>BLANK WordPress&#160;Theme</title>
		<link>http://digwp.com/2010/02/blank-wordpress-theme/</link>
		<comments>http://digwp.com/2010/02/blank-wordpress-theme/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 15:43:26 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[free]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=981</guid>
		<description><![CDATA[There are many like it, but this one is mine. I have a &#8220;blank&#8221; WordPress theme for myself, because I make a lot of WordPress themes. Starting from Kubrick, or any other pre-made theme, would be absurd. There is to much stuff there that would to be stripped out or fought against to be useful. [...]]]></description>
			<content:encoded><![CDATA[<p>There are many like it, but this one is mine. </p>
<p>I have a &#8220;blank&#8221; WordPress theme for myself, because I make a lot of WordPress themes. Starting from Kubrick, or any other pre-made theme, would be absurd. There is to much stuff there that would to be stripped out or fought against to be useful. So, I have my own. It&#8217;s been in a folder called BLANK-theme on my computer for a while, so I&#8217;m going to call it BLANK. And now I&#8217;m making it available for you. Read on to find out the scoop on it and you can decide if it would be of any use to you.</p>
<p><span id="more-981"></span></p>
<h3>What is BLANK?</h3>
<p>It is a WordPress theme with all the functionality of a typical WordPress theme but almost none of the styling. The idea is that when starting a new theme, it is far easier to use this as a base then a theme that is already finished and styled.</p>
<h3>What are some of it&#8217;s &#8220;features&#8221;?</h3>
<ul>
<li>Things are as semantically marked up as can be for a starter theme.</li>
<li>It&#8217;s XHTML 1.0 STRICT and validates. Maybe it will go HTML5 soon. We&#8217;re at that point where there isn&#8217;t a whole ton of advantages to going to HTML5 yet, but there aren&#8217;t many downsides either and it&#8217;s definitely the future.</li>
<li>The sidebar is widget-ready.</li>
<li>Page titles are optimized for best SEO and readability/usability.</li>
<li>Functions.php file does a number of things:  Sets up RSS &lt;link>&#8217;s in the head automatically, loads jQuery, removes the weird header links like rsd_link, wlw manifest, and generator info that I&#8217;ve never once needed, and registers the sidebar widget area.</li>
<li>Has some starter CSS ready to go, more about that below.</li>
<p>Uses <code>includes</code> for some key things, like under-title meta data and forward/back navigation, that are very common places for redundant code in themes.
</ul>
<h3>About the CSS</h3>
<p>As you can see from the screenshot above, the CSS is pretty baron, but not entirely! Here are some things the CSS is set up for:</p>
<ul>
<li>Uses a basic star-selector reset.</li>
<li>Includes a .group selector for the new clearfix</li>
<li>Has basic toolbox and WordPress-standard CSS classes, including .screen-reader-text for hiding things.</li>
<li>Standard typography-related sectors are there but generally without any attributes.</li>
<li>CSS for threaded comments is in there, but light on actual styling.</li>
<li>Both screen and print styles included in single stylesheet. Print styles optimized for generic nice printing.</li>
</ul>
<h3>Demo and Download</h3>
<p><img src="http://digwp.com/wp-content/blog-images/blank-theme-example.jpg" width="590" height="475" alt="" title="" /></p>
<p>If you want to take a peak at it live, you can <a href="http://themeclubhouse.digwp.com/index.php?wptheme=BLANK%20Theme">view it in our Theme Playground</a>. You can also download it from there, or <a href="http://themeclubhouse.digwp.com/themes/BLANK/BLANK-Theme-v1.zip">directly right here</a>. </p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/02/blank-wordpress-theme/">Permalink</a> | <a href="http://digwp.com/2010/02/blank-wordpress-theme/#comments">58 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/02/blank-wordpress-theme/&title=BLANK WordPress&nbsp;Theme">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <a href="http://digwp.com/tag/css/" rel="tag">CSS</a>, <a href="http://digwp.com/tag/free/" rel="tag">free</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/02/blank-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>How to Widgetize Your WordPress Theme in 2&#160;Steps</title>
		<link>http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/</link>
		<comments>http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 17:47:30 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1379</guid>
		<description><![CDATA[Working on a new theme for the next Digging into WordPress book update, I found myself really getting into the whole &#8220;widgetizing&#8221; thing. Widgets enable non-technical users to customize your theme according to their specific layout needs, and with so many different widgets available, the possibilities are endless. You may have thought about widgets as [...]]]></description>
			<content:encoded><![CDATA[<p>Working on a new theme for the next Digging into WordPress book update, I found myself really getting into the whole &ldquo;widgetizing&rdquo; thing. Widgets enable non-technical users to customize your theme according to their specific layout needs, and with <a href="http://codex.wordpress.org/WordPress_Widgets" title="WordPress Widgets">so many</a> different widgets available, the possibilities are endless. You may have thought about widgets as something you do in the sidebar, but there is no reason to stop there. You can widgetize just about every part of your theme. In this post, we&rsquo;ll show you how to do widgetize your theme in <strong>two easy steps</strong>. Once we get the basics down, we&rsquo;ll dig into some <em>sweet tips and tricks</em>.</p>
<p><span id="more-1379"></span></p>
<h3>Widgetize Your WordPress Theme: Step 1</h3>
<p>Make a fist and howl at the monitor. Then place this code into your active theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>if (function_exists('register_sidebar')) {

	register_sidebar(array(
		'name' =&gt; 'Widgetized Area',
		'id'   =&gt; 'widgetized-area',
		'description'   =&gt; 'This is a widgetized area.',
		'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
		'after_widget'  =&gt; '&lt;/div&gt;',
		'before_title'  =&gt; '&lt;h4&gt;',
		'after_title'   =&gt; '&lt;/h4&gt;'
	));

}</code></pre>
<p>This is all that is needed for the first step. Once this widgetizing code is placed in your <code>functions.php</code> file, proceed to Step 2. The remainder of this section is explanation.</p>
<p>This code checks to make sure that the current version of WordPress supports widgets, and then declares an array of values that will be used to create the widgetized area in your theme. Here are the different values:</p>
<ul>
<li><code>name</code> &ndash; the name of the widgetized area as displayed in the <acronym title="WordPress">WP</acronym> Admin</li>
<li><code>id</code> &ndash; a unique identifier for your widgetized area</li>
<li><code>description</code> &ndash; description of the widgetized area</li>
<li><code>before_widget</code> &ndash; the markup generated before any user-added widgets</li>
<li><code>after_widget</code> &ndash; the markup generated after any user-added widgets</li>
<li><code>before_title</code> &ndash; the markup generated before the title of any user-added widgets</li>
<li><code>after_title</code> &ndash; the markup generated after the title of any user-added widgets</li>
</ul>
<p>So, given these parameters, our widgetizing code would result in the following output, say, if the built-in Search widget were added to our widgetized area:</p>
<pre><code>&lt;div id="search-3" class="widget widget_search"&gt;
	&lt;h4&gt;Search&lt;/h4&gt;
	&lt;form role="search" method="get" id="searchform" action="http://localhost/283/" &gt;
		&lt;div&gt;
			&lt;label class="screen-reader-text" for="s"&gt;Search for:&lt;/label&gt;
			&lt;input type="text" value="" name="s" id="s" /&gt;
			&lt;input type="submit" id="searchsubmit" value="Search" /&gt;
		&lt;/div&gt;
	&lt;/form&gt;
&lt;/div&gt;</code></pre>
<p>Note the markup created for the opening <code>&lt;div&gt;</code>, which gets its attribute information based on the wild-card matching specified in our widgetizing array. To see this more clearly, examine the following side-by-side comparison of the <code>sprintf</code> directives and the resulting <acronym title="(eXtensible) Hypertext Markup Language">(X)HTML</acronym> source code:</p>
<pre><code>'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
&lt;div id="search-3" class="widget widget_search"&gt;</code></pre>
<p>Hopefully the relationship is clear. This is a powerful way to ensure that all widgets have a similar class names and unique <acronym title="Identification">ID</acronym>s, which are important for easy <acronym title="Cascading Style Sheets">CSS</acronym> styles.</p>
<p>Let&rsquo;s continue with Step 2..</p>
<h3>Widgetize Your WordPress Theme: Step 2</h3>
<p>Finally, add the following code to the location in your theme&rsquo;s template file(s) where you would like the widgetized area to appear:</p>
<pre><code>&lt;div id="widgetized-area"&gt;

	&lt;?php if (function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('widgetized-area')) : else : ?&gt;

	&lt;div class="pre-widget"&gt;
		&lt;p&gt;&lt;strong&gt;Widgetized Area&lt;/strong&gt;&lt;/p&gt;
		&lt;p&gt;This panel is active and ready for you to add some widgets via the WP Admin&lt;/p&gt;
	&lt;/div&gt;

	&lt;?php endif; ?&gt;

&lt;/div&gt;</code></pre>
<p>With both steps complete, your theme should now feature a widgetized area in the location of your choosing. Nothing else needs to be done at this point. If you get it, then get to it and continue developing your theme. For more information and some juicy tips and tricks, continue reading.</p>
<p>Let&rsquo;s examine the code used in this second step. Everything located between the <code>if</code>/<code>endif</code> statements will be output to the browser when no widgets have been activated. This is a good place to inform the user that the area is widgetized and may be customized via the Widgets area in the WordPress Admin. I also include a &ldquo;<code>pre-widget</code>&rdquo; class to help style the pre-widget area. With multiple widgetized areas on a page, having a class name to hang styles on is super nice.</p>
<p>Also, note that we are using the <code>id</code> specified in the widgetizing array (refer to Step 1) as the parameter value for the specific <code>dynamic_sidebar()</code> check in the third line.</p>
<h3>Multiple widgetized areas</h3>
<p>So we now have a nice, widgetized sidebar. But why stop there? Implementing additional widgetized areas is as simple as replicating the code in Step 1 and Step 2. For example, let&rsquo;s say we wanted to widgetize the header, sidebar, and footer areas of our theme. We would be put this in our <code>functions.php</code> file:</p>
<pre><code>if (function_exists('register_sidebar')) {

	register_sidebar(array(
		'name' =&gt; 'Header',
		'id'   =&gt; 'header',
		'description'   =&gt; 'This is the widgetized header.',
		'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
		'after_widget'  =&gt; '&lt;/div&gt;',
		'before_title'  =&gt; '&lt;h4&gt;',
		'after_title'   =&gt; '&lt;/h4&gt;'
	));
	register_sidebar(array(
		'name' =&gt; 'Sidebar',
		'id'   =&gt; 'sidebar',
		'description'   =&gt; 'This is the widgetized sidebar.',
		'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
		'after_widget'  =&gt; '&lt;/div&gt;',
		'before_title'  =&gt; '&lt;h4&gt;',
		'after_title'   =&gt; '&lt;/h4&gt;'
	));
	register_sidebar(array(
		'name' =&gt; 'Footer',
		'id'   =&gt; 'footer',
		'description'   =&gt; 'This is the widgetized footer.',
		'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
		'after_widget'  =&gt; '&lt;/div&gt;',
		'before_title'  =&gt; '&lt;h4&gt;',
		'after_title'   =&gt; '&lt;/h4&gt;'
	));

}</code></pre>
<p>..and then we would place the following code chunks into their respective locations within our theme template files:</p>
<pre><code>&lt;div id="widgetized-header"&gt;

	&lt;?php if (function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('header')) : else : ?&gt;

	&lt;div class="pre-widget"&gt;
		&lt;p&gt;&lt;strong&gt;Widgetized Header&lt;/strong&gt;&lt;/p&gt;
		&lt;p&gt;This panel is active and ready for you to add some widgets via the WP Admin&lt;/p&gt;
	&lt;/div&gt;

	&lt;?php endif; ?&gt;

&lt;/div&gt;
&lt;div id="widgetized-sidebar"&gt;

	&lt;?php if (function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('sidebar')) : else : ?&gt;

	&lt;div class="pre-widget"&gt;
		&lt;p&gt;&lt;strong&gt;Widgetized Sidebar&lt;/strong&gt;&lt;/p&gt;
		&lt;p&gt;This panel is active and ready for you to add some widgets via the WP Admin&lt;/p&gt;
	&lt;/div&gt;

	&lt;?php endif; ?&gt;

&lt;/div&gt;
&lt;div id="widgetized-footer"&gt;

	&lt;?php if (function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('footer')) : else : ?&gt;

	&lt;div class="pre-widget"&gt;
		&lt;p&gt;&lt;strong&gt;Widgetized Footer&lt;/strong&gt;&lt;/p&gt;
		&lt;p&gt;This panel is active and ready for you to add some widgets via the WP Admin&lt;/p&gt;
	&lt;/div&gt;

	&lt;?php endif; ?&gt;

&lt;/div&gt;</code></pre>
<p>That&rsquo;s all there is to it. Of course, you&rsquo;ll probably want to tweak the details to suit your specific needs, but these two steps are all you need to widgetize your WordPress theme. Now let&rsquo;s wrap things up with some juicy widgetizing tricks..</p>
<h3>Some Juicy Widgetizing Tricks</h3>
<p>Here are some sweet little tips for widgetizing your theme:</p>
<h4>Streamline &amp; organize custom widgets</h4>
<p>The first thing that I do after widgetizing a new theme is to include a separate &ldquo;<code>widgets.php</code>&rdquo; that contains all of the custom widgets. A simple line of code is all that is required to acheive this functionality:</p>
<p><code>if ($wp_version &gt;= 2.8) require_once(TEMPLATEPATH.'/widgets.php');</code></p>
<p>Place that code into your <code>functions.php</code> file and place all of your widgets into a file called <code>widgets.php</code>. Once in place, this method will ensure that your widgets are loaded and available for all supportive versions of WordPress. This is a great way to keep your theme files nice and organized.</p>
<h4>Replace WordPress&rsquo; default widgets</h4>
<p>Many of the default WordPress widgets leave something to be desired. Fortunately, it&rsquo;s super-easy to override any of the default widgets with your own creations. For example, here is one way to replace the default Search Widget with your own version:</p>
<pre><code>&lt;?php function custom_search_widget() { ?&gt;

&lt;form action="http://localhost/283/index.php" method="get"&gt;
	&lt;div&gt;
		&lt;label for="s"&gt;Site Search&lt;/label&gt;
		&lt;input id="s" name="s" alt="Search" type="text" /&gt;
	&lt;/div&gt;
&lt;/form&gt;

&lt;?php } if (function_exists('register_sidebar_widget'))

register_sidebar_widget(__('Search'), 'custom_search_widget'); ?&gt;</code></pre>
<h4>Hide unused widget areas</h4>
<p>An empty widgetized area of your theme can look strange, especially when <acronym title="Cascading Style Sheets">CSS</acronym> styles are applied to the container element. To prevent this from happening, we can wrap each of our widgetized areas with the following code:</p>
<pre><code>&lt;?php if (function_exists('is_sidebar_active') &amp;&amp; is_sidebar_active('sidebar')) { ?&gt;

&lt;!-- code from Step 2 or whatever you want --&gt;

&lt;?php } ?&gt;</code></pre>
<p>With this conditional code, widgetized areas will only be displayed if they contain at least one active widget. Nice&nbsp;:) Also note that this conditional technique works for displaying things other than widgets.</p>
<h3>More..?</h3>
<p>Hopefully this easy two-step widgetizing guide will be useful for you during your next round of theme development. As always, if you know of any other sweet widgetizing tricks, please share them in the comments!</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/">Permalink</a> | <a href="http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/#comments">24 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/&title=How to Widgetize Your WordPress Theme in 2&nbsp;Steps">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a>, <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Cool Things You can do with the WordPress &#8220;more&#8221;&#160;Tag</title>
		<link>http://digwp.com/2010/01/wordpress-more-tag-tricks/</link>
		<comments>http://digwp.com/2010/01/wordpress-more-tag-tricks/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 16:58:47 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[more-tag]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1185</guid>
		<description><![CDATA[Our personal collection of useful ways to customize and format the WordPress more tag&#8230; Everyone who has been using WordPress for any length of time should be familiar with the &#60;!--more--&#62; tag. When you are writing a post, inserting the &#60;!--more--&#62; tag within the post text will create an excerpt out of any text/markup that [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Our personal collection of useful ways to customize and format the WordPress <code>more</code> tag&#8230;</p></blockquote>
<p>Everyone who has been using WordPress for any length of time should be familiar with the <code>&lt;!</code><code>--more--&gt;</code> tag. When you are writing a post, inserting the <code>&lt;!</code><code>--more--&gt;</code> tag within the post text will create an excerpt out of any text/markup that precedes it. The post will then show the default &ldquo;<a href="#">more&#8230;</a>&rdquo; link that readers may click to view the entire post. When the <code>more</code> tag is used, the post&rsquo;s excerpt will be displayed on all non-single views, such as category, tag, and archive views; the entire post content will only be displayed when the single-post view is displayed. Let&rsquo;s look at a quick example..</p>
<p><span id="more-1185"></span></p>
<h3>A quick example of how to use the <code>more</code> tag</h3>
<p><strong>If you have the following post text:</strong></p>
<pre><code>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. 
Quisque volutpat mattis eros. Nullam malesuada erat ut turpis mattis.
Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.

&lt;!-more-&gt;

Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer 
ligula vulputate sem tristique cursus. Nam nulla quam, gravida non dolor, 
commodo a semper suscipit, sodales sit amet, nisi adipiscing.</code></pre>
<p><strong>..your post will show this on all non-single post views:</strong></p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.<br />
Quisque volutpat mattis eros. Nullam malesuada erat ut turpis mattis.<br />
Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p>
<p><a href="#">more&#8230;</a></p>
<p><strong>..and this on all single-post views:</strong></p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.<br />
Quisque volutpat mattis eros. Nullam malesuada erat ut turpis mattis.<br />
Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p>
<p>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer<br />
ligula vulputate sem tristique cursus. Nam nulla quam, gravida non dolor,<br />
commodo a semper suscipit, sodales sit amet, nisi adipiscing.</p>
<p>..which basically shows the entire post <em>without</em> the <code>more</code> link.</p>
<h3>Why do we use the <code>more</code> tag?</h3>
<p>Well mostly because excerpts are cool, and you can display many of them on your home page to give visitors a good overview of your content without making them scroll forever to do so. If one of your excerpts catches the visitor&rsquo;s eye, they will most likely want to read the entire post, and can do so by clicking on the link created by the <code>more</code> tag. To help encourage this behavior, there are several ways to customize the <code>more</code> link text, depending on your specific design goals. Let&rsquo;s take a look..</p>
<h3>Customize the <code>more</code> link text on a post-by-post basis</h3>
<p>There are a couple of good ways to customize the output format of your <code>more</code> link text. By far, the easiest way is to simply include your custom text right there in the <code>more</code> tag within your post text. For example, if you wanted to change your <code>more</code> text from the default to &ldquo;Keep reading this post&rdquo;, you would replace the usual <code>&lt;!</code><code>--more--&gt;</code> tag with this:</p>
<pre><code>&lt;!--more Keep reading this post--&gt;</code></pre>
<p>This way, WordPress makes it easy to customize <em>any</em> post&rsquo;s <code>more</code> link with unique text. This is one of those sweet WordPress secrets that not many people know about, as evidenced by the popular alternative method for customizing per-post <code>more</code> text:</p>
<pre><code>&lt;?php $custom_more = get_post_meta($post-&gt;ID, "custom_more_text", true);
if(!$custom_more) { $custom_more = "Keep reading this post &amp;raquo;"; }
the_content($custom_more); ?&gt;</code></pre>
<p>This code looks for a custom field named &ldquo;<code>custom_more_text</code>&rdquo; and displays its value as the post&rsquo;s custom <code>more</code> text. But again, this is complete overkill thanks to the previous method.</p>
<h3>Customize the <code>more</code> link text on a sitewide basis</h3>
<p>Instead of customizing <em>individual</em> <code>more</code> text, we can also customize it for <em>all</em> posts on a sitewide basis. The first and easiest way to change the default <code>more</code> link text is to simply add your custom text to <code>the_content()</code> template tag:</p>
<pre><code>&lt;?php the_content('Keep reading this post'); ?&gt;</code></pre>
<p>You can even add markup to help format and style the output according to your needs:</p>
<pre><code>&lt;?php the_content("&lt;span class="custom-more"&gt;Keep reading this post&lt;/span&gt;"); ?&gt;</code></pre>
<p>I think most WordPress peeps are familiar with this method and use it frequently. But there is also a newer method for accomplishing the same thing from the <code>functions.php</code> file. As of WordPress 2.8, we now may filter sitewide <code>more</code> links using the new filter hook, <code>the_content_more_link</code>:</p>
<pre><code>function my_more_link($more_link, $more_link_text) {
	return str_replace($more_link_text, 'Keep reading this post', $more_link);
}
add_filter('the_content_more_link', 'my_more_link', 10, 2);</code></pre>
<p>That goes into your theme&rsquo;s <code>functions.php</code> file. Simply edit the &ldquo;<code>Keep reading this post</code>&rdquo; string to whatever you would like to use for your custom <code>more</code> text. This is a good way to change your theme&rsquo;s <code>more</code> text without modifying any theme template files &#8212; perfect for customization via child themes! <a href="http://justintadlock.com/archives/2009/07/01/how-to-filter-a-wordpress-themes-more-link-text" title="How to filter a WordPress theme’s 'more link' text">Check out Justin Tadlock&rsquo;s article for more information</a>.</p>
<h3>Automatically display the post title in <code>more</code> links</h3>
<p>Another cool <code>more</code>-tag trick is to include the post title in the <code>more</code> link text. For example, we might want to setup something like this:</p>
<p>Lorem ipsum..</p>
<p><a href="#">Continue reading &ldquo;Lorem Ipsum Strikes Back&rdquo;</a></p>
<p>Including the post title into your <code>more</code> links is a great way to personalize each excerpt with a little &ldquo;more&rdquo; (haha). Anyway, here is how the Codex suggests doing this:</p>
<pre><code>&lt;?php the_content("...continue reading the story called " . get_the_title('', '', false)); ?&gt;</code></pre>
<p>That&rsquo;ll work, but we can clean it up a little like so:</p>
<pre><code>&lt;?php the_content(the_title('Continue reading &amp;ldquo;','&amp;rdquo;',false)); ?&gt;</code></pre>
<p>That&rsquo;s a tight little snippet that will generate custom <code>more</code> links that include the title of the associated post. Nice.</p>
<h3>Stop <code>more</code> link from jumping to middle of page</h3>
<p>By default, clicking on the <code>more</code> link will take the reader to the single-post view <strong>at the location where the <code>more</code> tag is specified in the source code</strong>. Thus, if you are using default <code>more</code>-tag functionality, your visitors are being thrown halfway-down your post after clicking on the <code>more</code> link. At one time, this seemed like a good idea, but the convention is now to simply open the post-view without jumping to any particular point in the page. </p>
<p>All of that to say this: if you want the <code>more</code> link to open the post-view at the <em>top</em> of the page, slap this little gem into your active theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>function remove_more_jump_link($link) { 
	$offset = strpos($link, '#more-');
	if ($offset) {
		$end = strpos($link, '"',$offset);
	}
	if ($end) {
		$link = substr_replace($link, '', $offset, $end-$offset);
	}
	return $link;
}
add_filter('the_content_more_link', 'remove_more_jump_link');</code></pre>
<p>This will kill the <code>more</code> &ldquo;jump&rdquo; and keep visitors from being thrown around the page unexpectedly. Note that this function is only for WordPress version 2.8 and better. For older versions, you&rsquo;re gonna need to hack the core. See the <a href="http://codex.wordpress.org/Customizing_the_Read_More/#Link_Jumps_to_More_or_Top_of_Page" title="Customizing the Read More: Link Jumps to More or Top of Page">Codex</a> for more information.</p>
<h3>Target custom pages with the <code>more</code> tag</h3>
<p>The typical use of the <code>more</code> tag is such that its link opens the single-view of the associated post. This may be changed, however, should you ever need to target a different web page. To understand this a bit better, consider the parameters available to <code>the_content()</code> template tag:</p>
<pre><code>&lt;?php the_content($more_link_text, $strip_teaser, $more_file); ?&gt;</code></pre>
<p>Here, the <code>$more_link_text</code> parameter defines the text that will be used for the <code>more</code> link. The <code>$strip_teaser</code> parameter defines a boolean value determining whether or not to display the <code>more</code> link. The third parameter is the one we&rsquo;re interested in here. The <code>$more_file</code> parameter specifies the <acronym title="Uniform Resource Locator">URL</acronym> that the <code>more</code> link should reference. By default, this <acronym title="Uniform Resource Locator">URL</acronym> points to the associated single-view post, but we could just as easily customize this like so:</p>
<pre><code>&lt;?php the_content('Order Now!', FALSE, 'http://amazing-product.com/order-page.html'); ?&gt;</code></pre>
<p>Or whatever. Obviously, the uses for this are limited, but it&rsquo;s there if you ever need it.</p>
<h3>Styling the <code>more</code> link</h3>
<p>The easiest way to style the <code>more</code> tag is to take advantage of the built-in class attribute, <code>more-link</code>. By default, this class is automatically included on every WordPress <code>more</code> link in the entire world. Thus, you can apply styles directly, for example:</p>
<pre><code>.more-link {
	border: thin solid black;
	letter-spacing: 1px;
	background: yellow;
	font-size: 24px;
	color: red;
	}</code></pre>
<p>If you need additional control, you may also incorporate custom markup to your <code>more</code> link via <code>the_content()</code> template tag:</p>
<pre><code>&lt;?php the_content("&lt;span class="custom-more"&gt;Keep reading &lt;em&gt;this&lt;/em&gt; post&lt;/span&gt;"); ?&gt;</code></pre>
<p>Which would output markup such that the following <acronym title="Cascading Style Sheets">CSS</acronym> could be applied:</p>
<pre><code>.custom-more {
	font-weight: bolder;
	}
	.custom-more em {
		font-weight: normal;
		font-style: italic;
		}</code></pre>
<p>Obviously, this is just a simple example to help illustrate the method. Just about anything is possible!</p>
<h3>Adding an image to your <code>more</code> link</h3>
<p>Last but not least, let&rsquo;s wrap up the article with a couple of ways to add an image to your <code>more</code> link. The first way to do it is to simply include the image element directly in <code>the_content()</code> template tag:</p>
<pre><code>&lt;?php the_content('&lt;img src="http://domain.tld/read-more.png" alt="Arrow" title="Read more" /&gt;'); ?&gt;</code></pre>
<p>This will spit out an image for your more tag instead of text. You could also add in some text, but if you don&rsquo;t be sure to include the <code>alt</code> and <code>title</code> attributes for the <code>&lt;img&gt;</code> element. Either way, you can also style your &ldquo;Read more&rdquo; image using some <acronym title="Cascading Style Sheets">CSS</acronym>, or even bypass the <code>&lt;img&gt;</code> element completely and add an image using a few lines of <acronym title="Cascading Style Sheets">CSS</acronym>:</p>
<pre><code>.more-link img {
	background:url(http://domain.tld/read-more.png) no-repeat left center;
	padding: 10px;
	height: 100px;
	width: 300px;
	}</code></pre>
<p>Again, just an example demonstrating how it works. The possibilities here are virtually infinite.</p>
<h3>&ldquo;I give myself a B+&rdquo;</h3>
<p>It would have been an &ldquo;A&rdquo;, but I just <em>know</em> there are <em>more</em> cool things you can do with the WordPress <code>more</code> tag. This article shares all of the cool tricks that we know, but there&rsquo;s just <em>got</em> to be <strong>more</strong> sweet tips! Hopefully you know of some more <code>more</code> tricks to share with the WordPress community&nbsp;;) &ndash; Chime in!</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/01/wordpress-more-tag-tricks/">Permalink</a> | <a href="http://digwp.com/2010/01/wordpress-more-tag-tricks/#comments">26 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/01/wordpress-more-tag-tricks/&title=Cool Things You can do with the WordPress &#8220;more&#8221;&nbsp;Tag">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <a href="http://digwp.com/tag/more-tag/" rel="tag">more-tag</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/01/wordpress-more-tag-tricks/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>How to Develop WordPress Themes Behind the&#160;Scenes</title>
		<link>http://digwp.com/2009/12/develop-themes-behind-the-scenes/</link>
		<comments>http://digwp.com/2009/12/develop-themes-behind-the-scenes/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 07:16:07 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[theme-switch]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1104</guid>
		<description><![CDATA[A reader recently asked about how to develop a theme on a live site such that: All visitors will see the current theme Only the designer will see the new theme All site plugins will work with the new theme Smooth transition between old and new theme at launch These are the main concerns, but [...]]]></description>
			<content:encoded><![CDATA[<p>A reader recently asked about how to develop a theme on a live site such that:</p>
<ul>
<li>All visitors will see the current theme</li>
<li>Only the designer will see the new theme</li>
<li>All site plugins will work with the new theme</li>
<li>Smooth transition between old and new theme at launch</li>
</ul>
<p>These are the main concerns, but there are a few other details that need addressed to ensure smooth theme development on a live site. Let&rsquo;s take a look at how to achieve these goals and effectively develop themes behind the scenes..</p>
<p><span id="more-1104"></span></p>
<h3>You need a plugin</h3>
<p>The easiest way to develop a new theme behind the scenes is to install a good theme-switcher plugin. There are plenty available:</p>
<ul>
<li><a href="http://wordpress.org/extend/plugins/theme-switcher/" title="Theme Switcher">Theme Switcher</a></li>
<li><a href="http://wordpress.org/extend/plugins/theme-switcher-reloaded/" title="Theme Switcher Reloaded">Theme Switcher Reloaded</a></li>
<li><a href="http://wordpress.org/extend/plugins/alternative-theme-switcher/" title="Alternative Theme Switcher">Alternative Theme Switcher</a></li>
<li><a href="http://wordpress.org/extend/plugins/theme-preview/" title="Theme Preview">Theme Preview</a>
<li><a href="http://wordpress.org/extend/plugins/theme-test-drive/" title="Theme Test Drive">Theme Test Drive</a></li>
<li><a href="http://wordpress.org/extend/plugins/nkthemeswitch/" title="Theme Switch and Preview">NK Theme Switch</a></li>
</ul>
<p>Any of these plugins will work fine for the purposes of working with multiple themes on your site. If you also plan on enabling your visitors to switch themes, I would have to recommend the newer NK Theme Switch plugin. NK Theme Switch does everything the other plugins can do, but with the added bonus that it redirects users back to the page from which they came after switching themes. The other two plugins switch themes, but the user is always redirected back to the home page after the theme switch. </p>
<p>Note that, for the different theme-switcher plugins, the <acronym title="Uniform Resource Locator">URL</acronym>s used when switching themes include different query-string parameters that are similar but not interchangeable. Once you implement a theme switcher, replacing it with a different plugin is going to be difficult.</p>
<p>In any case, once you have your theme-switcher plugin of choice activated, you&rsquo;re going to need to know how to actually switch the themes..</p>
<h3>Switching themes</h3>
<p>Different plugins involve different methods of switching to a different theme. If you are using NK Theme Switch, you can select and activate your alternate (development) theme from within the WordPress Admin. This is the <em>easiest</em> way to do it. If you are using one of the other theme-switching plugins, activating the alternate theme for your browser is as easy as entering a specific <acronym title="Uniform Resource Locator">URL</acronym> into the address bar. These theme-switching <acronym title="Uniform Resource Locator">URL</acronym>s look similar for either of the first two plugins:</p>
<pre><code>http://domain.tld/index.php?wptheme=ThemeName</code></pre>
<p>For example, here is the <acronym title="Uniform Resource Locator">URL</acronym> used to switch to one of my favorite themes at <a href="http://perishablepress.com/" title="Perishable Press: Digital Design and Dialogue">Perishable Press</a>:</p>
<pre><code>http://perishablepress.com/press/index.php?wptheme=Perishable</code></pre>
<p>The syntax here is straightforward &#8212; the only thing that needs to be changed is the theme name, which in this case is &ldquo;Perishable&rdquo;. When developing a new theme for Perishable Press, I simply jot down the theme-switch <acronym title="Uniform Resource Locator">URL</acronym> for both the new theme and the active default theme. This makes jumping back and forth very easy. Of course, the general format of these <acronym title="Uniform Resource Locator">URL</acronym>s will vary depending on the particular theme-switching plugin that you use.</p>
<p>Another option for switching between current and alternate themes is to actually include the theme-switching links and/or dropdown menu right there on the theme pages themselves. For example, including the theme-switch dropdown menu in the footer of all your themes is a great way to speed up and simplify the development process. But be advised, unless you explicitly <em>exclude</em> your new theme from the theme-switch menu, it will be available for all of your visitors to see and activate. The other method of just using the <acronym title="Uniform Resource Locator">URL</acronym> directly is a good way to ensure privacy.</p>
<p>Now that you are setup and easily switching between themes, there are a few other points to consider..</p>
<h3>Your new theme is just another theme</h3>
<p>This may sound strange, but there is nothing special about your new theme &#8212; it&rsquo;s treated by WordPress as any other theme in your &ldquo;<code>themes</code>&rdquo; directory. All of the requirements of the default theme apply:</p>
<ul>
<li>Your new theme needs a properly configured <code>style.css</code> file</li>
<li>Your new theme needs a working <code>index.php</code> file</li>
</ul>
<p>Assuming your new theme meets these basic requirements, WordPress will recognize your theme as such and display it when activated (either through the Admin or via theme-switch plugin). Incidentally, the name of your theme is specified via the <code>style.css</code> file. The &ldquo;<code>Theme Name</code>&rdquo; that is listed here will be the same one used in your theme-switching <acronym title="Uniform Resource Locator">URL</acronym>s.</p>
<p>Once you get the basics of your new theme established, use your theme-switching plugin to activate it locally in your browser. Form there, you can rock the design however you want, exactly as you would do when starting from a fresh installation of WordPress. While you are working on your new theme, your visitors will still be seeing your default active theme, which is whatever you specify in the WordPress Admin. This is why the theme-switch development method works so well.</p>
<h3>Pages, plugins, and custom functions</h3>
<p>Here are a few more little things that will help you when developing your themes behind the scenes..</p>
<dl>
<dt>Plugins affect <em>all</em> themes</dt>
<dd>Even when your theme is not set as the current default, it will still be affected by all of the plugins installed on your site. This is one of the benefits of using plugins over custom functions..</dd>
<dt>Custom functions only affect the theme being used</dt>
<dd>In contrast to plugins, custom functions (i.e., functions placed in your theme&rsquo;s <code>functions.php</code> file) only affect the current theme being viewed. If you seem to missing some functionality in your &ldquo;behind-the-scenes&rdquo; theme, make sure that you have properly transferred any required custom functions.</dd>
<dt>Page templates will confuse you</dt>
<dd>This happens to everyone: you are working behind the scenes on a new theme and you can&rsquo;t seem to get a custom page template to appear in the WordPress Admin. This is because the page editor only shows the templates available to the current default active theme (i.e., the one that <em>everyone</em> sees). To work around this, you can either upload a copy of the custom page template to the active theme, or temporarily switch the default active theme to your behind-the-scenes theme. Personally, I use the former method and just delete the page template if it&rsquo;s not needed in the default theme.</dd>
</dl>
<p>And last but not least..</p>
<h3>Prepare for launch!</h3>
<p>Once you have your new theme pimped out and ready to go, simply change your default active theme in the WordPress Admin to launch it for the world see. That&rsquo;s all there is to it!&nbsp;:)</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/12/develop-themes-behind-the-scenes/">Permalink</a> | <a href="http://digwp.com/2009/12/develop-themes-behind-the-scenes/#comments">27 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2009/12/develop-themes-behind-the-scenes/&title=How to Develop WordPress Themes Behind the&nbsp;Scenes">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/design/" title="View all posts in Design" rel="category tag">Design</a>, <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <a href="http://digwp.com/tag/plugin/" rel="tag">plugin</a>, <a href="http://digwp.com/tag/theme-switch/" rel="tag">theme-switch</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/12/develop-themes-behind-the-scenes/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Display Gravatar &amp; Autofill Fields for Previous&#160;Commenter</title>
		<link>http://digwp.com/2009/12/gravatar-and-auto-fill/</link>
		<comments>http://digwp.com/2009/12/gravatar-and-auto-fill/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 14:24:22 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1063</guid>
		<description><![CDATA[When someone comments on your site, cookies with the information the entered are saved to their computers. WordPress makes it easy to access that information. In fact, in your comments.php template they are ready-to-go PHP variables you can spit out anywhere you&#8217;d like. Let&#8217;s take a look. Here are the most important ones, when it [...]]]></description>
			<content:encoded><![CDATA[<p>When someone comments on your site, cookies with the information the entered are saved to their computers. WordPress makes it easy to access that information. In fact, in your comments.php template they are ready-to-go PHP variables you can spit out anywhere you&#8217;d like. Let&#8217;s take a look.</p>
<p><span id="more-1063"></span></p>
<p>Here are the most important ones, when it comes to commenting, are these:</p>
<ul>
<li>$comment_author</li>
<li>$comment_author_email</li>
<li>$comment_author_url</li>
</ul>
<p>Which you can safely output anywhere in the comments.php file like so:</p>
<pre><code>&lt;?php echo esc_attr($comment_author); ?&gt;
&lt;?php echo esc_attr($comment_author_email); ?&gt;
&lt;?php echo esc_attr($comment_author_url); ?&gt;</code></pre>
<p>In order to pre-fill the comment form with this information, the inputs for your comment form could be marked up like so:</p>
<pre><code>&lt;div&gt;
  &lt;label for="author"&gt;Name*&lt;/label&gt;
  &lt;input type="text" name="author" id="author" value="&lt;?php echo esc_attr($comment_author); ?&gt;" tabindex="1" /&gt;			
&lt;/div&gt;	

&lt;div&gt;
  &lt;label for="email"&gt;Email*&lt;/label&gt;
  &lt;input type="text" name="email" id="email" value="&lt;?php echo esc_attr($comment_author_email); ?&gt;" tabindex="2" /&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;label for="url"&gt;Website&lt;/label&gt;
  &lt;input type="text" name="url" id="url" value="&lt;?php echo esc_attr($comment_author_url); ?&gt;" tabindex="3" /&gt;
&lt;/div&gt;</code></pre>
<h3>Getting the Gravatar</h3>
<p>Gravatars are those little pictures that show up next to comments&#8230; &#8220;Globally Recognized Avatars&#8221;. Anybody can have one, <a href="http://en.gravatar.com/">get one here</a>. What is cool about Gravatars is you have your own account that is associated with your email, so anywhere you comment that you use that email that supports Gravatars, that image will show up, and you can &#8220;globally&#8221; change that image at any time. </p>
<p>It is almost trivially easy to grab the URL source of someone&#8217;s Gravatar. The direct link to the image is:</p>
<p>http://www.gravatar.com/avatar/MD5-HASH-OF-EMAIL</p>
<p>So to spit out an &lt;img&gt; in your comments.php file, use a little PHP:</p>
<pre><code>&lt;?php if ($comment_author_email != "") { 

    $gravatar_link = 'http://www.gravatar.com/avatar/' . md5($comment_author_email) . '?s=32';
    echo '&lt;img src="' . $gravatar_link . '" alt="" /&gt;';

} ?&gt;</code></pre>
<p>On CSS-Tricks, I use all of this to prefill previous commenter information, including a small Gravatar:</p>
<p><img src="http://digwp.com/wp-content/blog-images/prefill.png" width="558" height="86" alt="" title="" /></p>
<p>That&#8217;s all there is to it!  I think the comment form in every single WordPress theme ever written should probably use at least the pre-fill stuff. The &#8220;default&#8221; and &#8220;classic&#8221; themes that come with WordPress have this, so it&#8217;s pretty standard, but I do see plenty of themes that don&#8217;t.</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/12/gravatar-and-auto-fill/">Permalink</a> | <a href="http://digwp.com/2009/12/gravatar-and-auto-fill/#comments">9 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2009/12/gravatar-and-auto-fill/&title=Display Gravatar &#038; Autofill Fields for Previous&nbsp;Commenter">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/theme/" title="View all posts in Theme" rel="category tag">Theme</a> | Tagged: <a href="http://digwp.com/tag/comments/" rel="tag">comments</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/12/gravatar-and-auto-fill/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
