<?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>Justin Tadlock &#187; WordPress Tutorials</title>
	<atom:link href="http://justintadlock.com/tags/wordpress-tutorials/feed" rel="self" type="application/rss+xml" />
	<link>http://justintadlock.com</link>
	<description>Life, Blogging, and WordPress</description>
	<lastBuildDate>Sun, 07 Feb 2010 08:25:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Showing custom post types on your home/blog page</title>
		<link>http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page</link>
		<comments>http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page#comments</comments>
		<pubDate>Tue, 02 Feb 2010 08:22:47 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=2283</guid>
		<description><![CDATA[How to add custom post types to your blog post rotation on your WordPress home (blog/posts) page.]]></description>
			<content:encoded><![CDATA[<p>In the last few days, I&#8217;ve shown a few people a <a href="http://justintadlock.com/blog/wp-content/uploads/2010/02/justin-tadlock-future.png" title="Justin Tadlock future home page">screenshot</a> of something I&#8217;ve been working on for this site.  The screenshot is of a home page displaying custom post types and not just the <code>post</code> post type.  After numerous requests for the code to do this, I figured it&#8217;d be much easier to share it here.</p>
<p>WordPress version 3.0 will make creating <a href="http://core.trac.wordpress.org/ticket/9674" title="WordPress Trac: Better support for custom post types">custom post types</a> extremely simple.  But, the techniques I&#8217;ll point out in this tutorial can be used with previous versions of WordPress.</p>
<h2>Changing the post type on the home page</h2>
<p>By default, WordPress shows the <code>post</code> post type on your home page.  Let&#8217;s suppose we want to show several post types in addition to posts:</p>
<ul>
<li><code>page</code> (yes, regular pages)</li>
<li><code>album</code></li>
<li><code>movie</code></li>
<li><code>quote</code></li>
</ul>
<p>To add these, open your theme&#8217;s <code>functions.php</code> file and paste this <acronym title="Hypertext Preprocessor">PHP</acronym> code into it:</p>
<pre><code>add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

	if ( is_home() )
		$query->set( 'post_type', array( 'post', 'page', 'album', 'movie', 'quote', 'attachment' ) );

	return $query;
}</code></pre>
<p>That&#8217;s all there is to it.</p>
<p>You may have noticed the addition of the <code>attachment</code> post type even though I didn&#8217;t mention adding it.  This is something I highly recommend adding if you&#8217;ll be showing any attachment images on your home page  For example, if you have a gallery on your home page, the images won&#8217;t appear without adding the <code>attachment</code> post type.</p>
<h2>Showing the post types in your feed</h2>
<p>Realizing that many of you might want to also add these post types to your feed to match your blog, a small change in the code is required.  All you need to do is change this line:</p>
<pre><code>if ( is_home() )</code></pre>
<p>We&#8217;ll use the <code>is_feed()</code> conditional tag:</p>
<pre><code>if ( is_home() || is_feed() )</code></pre>
<p>Now, you can have custom post types in your regular blog post rotation and your feed.  Enjoy and look for more custom post type tutorials soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page/feed</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Sidebar (widget area) descriptions in WordPress 2.9</title>
		<link>http://justintadlock.com/archives/2009/11/24/sidebar-widget-area-descriptions-in-wordpress-2-9</link>
		<comments>http://justintadlock.com/archives/2009/11/24/sidebar-widget-area-descriptions-in-wordpress-2-9#comments</comments>
		<pubDate>Wed, 25 Nov 2009 02:05:41 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=2216</guid>
		<description><![CDATA[How to add descriptions to individual widget areas in WordPress 2.9 and why this is a useful feature for end users.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">H</span>ave you ever used a WordPress theme with more than a couple of widget areas?  More specifically, have you ever used a WordPress theme with loads of widget areas and no idea how they all worked within the theme?</p>
<p>If you&#8217;ve ever used a theme of mine, you know I love adding widget areas everywhere. And, I know this can be confusing for some people.</p>
<p>Fortunately, WordPress 2.9 will allow theme developers to add a description for each widget area.  This should help end users figure out what the heck is going on.</p>
<h2>Widget descriptions from a user&#8217;s view</h2>
<p>If you&#8217;re an end user and your theme author has added descriptions, you&#8217;ll see the description near the top of the widget area on the <em>Widgets</em> admin screen.</p>
<p><img src="http://justintadlock.com/blog/wp-content/uploads/2009/11/sidebar-descriptions.png" alt="Widget Area Descriptions" title="Widget Area Descriptions" width="600" height="428" class="aligncenter size-full wp-image-2217" /></p>
<h2>Adding descriptions to widget areas</h2>
<p>If you&#8217;re a theme developer, adding descriptions to your widget areas is as simple as adding an extra argument to the <code>register_sidebar()</code> function. Use the below <acronym title="Hypertext Preprocessor">PHP</acronym> code as a guide.</p>
<pre><code>add_action( 'init', 'register_my_widget_areas' );

function register_my_widget_areas() {

	register_sidebar( array(
		'name' => __('Primary', 'example'),
		'id' => 'primary',
		'description' => __('The main widget area, most often used as a sidebar.', 'example'),
		'before_widget' => '&lt;div id="%1$s" class="widget %2$s widget-%2$s">',
		'after_widget' => '&lt;/div>',
		'before_title' => '&lt;h3 class="widget-title">',
		'after_title' => '&lt;/h3>'
	) );
}</code></pre>
<p>The new code allowed in 2.9 is the <code>description</code> argument.</p>
<pre><code>'description' => __('The main widget area, most often used as a sidebar.', 'example'),</code></pre>
<p>Theme authors, it&#8217;s time to implement this new feature for your users.  It will take less than five minutes to add to your theme and should at least cut back on a few support queries.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/11/24/sidebar-widget-area-descriptions-in-wordpress-2-9/feed</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>Everything you need to know about WordPress 2.9&#8217;s post image feature</title>
		<link>http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature</link>
		<comments>http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature#comments</comments>
		<pubDate>Mon, 16 Nov 2009 07:50:08 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=2126</guid>
		<description><![CDATA[An in-depth look at how the post image feature in WordPress 2.9 can be used from the perspective of both end users and developers.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">Y</span>ou may have heard a bit of news about a new thumbnail feature for themes coming to WordPress 2.9.  Yes, you&#8217;ll be able to easily upload a post thumbnail.  However, it&#8217;s not just thumbnails.  The image will have various sizes.  So, I&#8217;m going to refer to this feature as the post image feature.</p>
<p>In this tutorial, I&#8217;ll be covering the various things you can do with the post image feature.  Some things will be specific to end users while others will be useful for theme and plugin developers.</p>
<p>One important thing to note is that this new feature is an image-based representation of a post.  The image itself is directly tied to your post.  You shouldn&#8217;t think of it as something different than that.</p>
<h2>How does an end user make use of this feature?</h2>
<p>First, your theme must add support for it.  Otherwise, you won&#8217;t be able to use it.  At this point, let&#8217;s assume that your theme does support it.  I&#8217;ll go over instructions for theme authors later.</p>
<p>To use this feature, you must be within the post editing screen of your WordPress admin.  On this screen, you&#8217;ll see a new meta box labeled &#8220;Post thumbnail&#8221; (or &#8220;Page thumbnail&#8221; for pages).  There&#8217;ll be a link to &#8220;Set thumbnail,&#8221; which will allow you to use the media uploader to load a new image.</p>
<p><img src="http://justintadlock.com/blog/wp-content/uploads/2009/11/the-post-image.png" alt="Screenshot of WordPress 2.9's post image uploader" title="The Post Image" width="600" height="429" class="aligncenter size-full wp-image-2127" /></p>
<h2>It&#8217;s not just for thumbnails</h2>
<p>Even though it is called &#8220;post thumbnails,&#8221; we can technically use the feature for all sorts of things (e.g., feature images, medium-sized images for the front page, etc.).</p>
<p>By default, WordPress gives you several image sizes each time you upload an image.  These image sizes are:</p>
<ul>
<li>Thumbnail</li>
<li>Medium</li>
<li>Large</li>
<li>Full (the image you uploaded)</li>
</ul>
<p>Some plugins even extend this by allowing more intermediate sizes.  The important thing is that you understand that more than thumbnails can be used here.</p>
<h2>How to add support for the post image feature in a theme</h2>
<p>Theme authors, I&#8217;m going to make this simple for you.  You only need one line of code to turn this feature on for your users.  Add this to your theme&#8217;s <code>functions.php</code> file:</p>
<pre><code>add_theme_support( 'post-thumbnails' );</code></pre>
<p>Or, you can register support for specific post types.  For example, let&#8217;s suppose you wanted to add thumbnail support for both the <code>post</code> and <code>movie</code> post type but not for the <code>page</code> post type.  You&#8217;d use this instead:</p>
<pre><code>add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );</code></pre>
<p>Of course, that one line doesn&#8217;t actually add anything to the front end for you.  You&#8217;ll need to call the image somewhere within The Loop in your template files.  For example, you might want to add thumbnails to your category archives.  You&#8217;d do this by adding this line of code:</p>
<pre><code>&lt;?php the_post_thumbnail( 'thumbnail' ); ?></code></pre>
<p>Or, maybe you have a section on a special template that calls for medium-sized images:</p>
<pre><code>&lt;?php the_post_thumbnail( 'medium' ); ?></code></pre>
<p>Or, a huge sliding feature area on your front page and need the full-sized image:</p>
<pre><code>&lt;?php the_post_thumbnail( 'full' ); ?></code></pre>
<p>That&#8217;s all there is to it.  As a theme author, you can hand over some powerful functionality to your users with just a couple of lines of code.</p>
<p>The rest of this tutorial will focus on developer features and some options for using older images.</p>
<h2>Checking if the post has an image</h2>
<p>Sometimes, you may need to check if a post has an image.  There&#8217;s a function for that called <code>has_post_thumbnail()</code>, which will return <code>true</code> or <code>false</code> based on whether there&#8217;s an image.</p>
<p>In this example, we&#8217;ll check if there&#8217;s an image.  If there&#8217;s not, we&#8217;ll show a default image instead.</p>
<pre><code>&lt;?php
	if ( has_post_thumbnail() )
		the_post_thumbnail( 'thumbnail' );
	else
		echo '&lt;img src="default-image.png" alt="Example Image" title="Example" />';
?></code></pre>
<h2>Getting the post image ID</h2>
<p>Maybe you need to write your own custom script but still want to allow users to upload their own images.  You can grab the post image ID and use it.  This ID is saved as the meta value for the meta key <code>_thumbnail_id</code>.  It is the ID of the attached file.</p>
<p>You only need to call the function in your code like so:</p>
<pre><code>$image_id = get_post_thumbnail_id();</code></pre>
<h2>How to return the image instead of displaying it</h2>
<p>In some scenarios, you might want to return the post image for use in your <acronym title="Hypertext Preprocessor">PHP</acronym> code instead of displaying it.</p>
<p>Here&#8217;s an example of that functionality:</p>
<pre><code>$image = get_the_post_thumbnail( $post->ID, 'thumbnail' );</code></pre>
<h2>How to filter the image size</h2>
<p>Some plugin developers may want to filter the image size (or maybe even child theme authors).  The <code>post_thumbnail_size</code> filter hook is available for that.  The filter function below is for changing the <code>thumbnail</code> size to <code>medium</code>.</p>
<p>Add this <acronym title="Hypertext Preprocessor">PHP</acronym> code to your theme&#8217;s <code>functions.php</code> file or your plugin file:</p>
<pre><code>add_filter( 'post_thumbnail_size', 'my_post_image_size' );

function my_post_image_size( $size ) {
	$size = 'medium';
	return $size;
}</code></pre>
<h2>Changing the <acronym title="Hypertext Markup Language">HTML</acronym> output of the post image</h2>
<p>There may be some scenarios where you&#8217;ll want to change the <acronym title="Hypertext Markup Language">HTML</acronym> markup of the displayed image.  In this example, I&#8217;ll show you how to wrap the image with a link to the post.</p>
<p>Add this <acronym title="Hypertext Preprocessor">PHP</acronym> code to your theme&#8217;s <code>functions.php</code> file or your plugin file:</p>
<pre><code>add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );

function my_post_image_html( $html, $post_id, $post_image_id ) {

	$html = '&lt;a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '&lt;/a>';

	return $html;
}</code></pre>
<h2>What happens to my old images/thumbnails?</h2>
<p>If you&#8217;re like me and many others, you may have been using custom fields to add images to your posts for years.  If you switch to this new method, everything will be lost.</p>
<p>I&#8217;ve got a solution for this problem:  The <a href="http://wordpress.org/extend/plugins/get-the-image" title="Get the Image WordPress plugin">Get the Image</a> plugin.</p>
<p>Version 0.4 will be released when WordPress 2.9 is out.  Not only will support be added for the new WordPress post image feature, but you won&#8217;t lose all of the hard work you&#8217;ve put in.  The plugin will have the ability to check for post images in five different ways (in the below order):</p>
<ul>
<li>Custom fields.</li>
<li>New post image feature.</li>
<li>Attached image.</li>
<li>Scan the post for images.</li>
<li>Default image.</li>
</ul>
<p>For those of you already using this plugin or a theme of mine that includes the script, you&#8217;ll only have to upgrade the plugin or theme.  The feature will be turned on for you by default, so you will be able to start using the new feature without touching anything but an upgrade button.</p>
<h2>Have fun with your new post images</h2>
<p>I hope this tutorial has given you an in-depth look at the post image feature.  There are <a href="http://www.binarymoon.co.uk/2009/10/wordpress-the_post_image/" title="WordPress 2.9 &mdash; the_post_image">some limitations</a>, but on the whole, this feature will make things much easier for end users compared to the currently-available methods.</p>
<p>If you&#8217;re a user of my <a href="http://wordpress.org/extend/plugins/get-the-image" title="Get the Image WordPress plugin">Get the Image plugin</a> or <a href="http://themehybrid.com/themes/hybrid" title="Hybrid theme framework">Hybrid theme</a>, look out for an update within a few days of WordPress 2.9.  You&#8217;ll be able to start using the post image functionality soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature/feed</wfw:commentRss>
		<slash:comments>131</slash:comments>
		</item>
		<item>
		<title>Excerpts and taxonomies for pages in WordPress 2.9</title>
		<link>http://justintadlock.com/archives/2009/11/09/excerpts-and-taxonomies-for-pages-in-wordpress-2-9</link>
		<comments>http://justintadlock.com/archives/2009/11/09/excerpts-and-taxonomies-for-pages-in-wordpress-2-9#comments</comments>
		<pubDate>Mon, 09 Nov 2009 10:11:00 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=2122</guid>
		<description><![CDATA[How to make use of a simple file change in WordPress 2.9 to add an excerpt box and custom taxonomy boxes to your page editor.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">W</span>hile the information in this tutorial <em>will</em> be focused on excerpts and taxonomies, the big change in WordPress 2.9 is that the meta box functions have been included in a new file: <code>/wp-admin/include/meta-boxes.php</code>.  This change allows us to do some fun things because the code is not limited to a single area anymore.</p>
<p>In this tutorial, you&#8217;ll learn how to utilize the <code>add_meta_box()</code> functionality to add two things to your pages:</p>
<ol>
<li>Excerpt box.</li>
<li>Custom taxonomies boxes.</li>
</ol>
<p>Being able to add these meta boxes to pages isn&#8217;t the limit.  This tutorial should serve as a starting point.  You could do the same for custom post types, links, or anything that fires the <code>do_meta_boxes</code> action hook.</p>
<h2>Adding an excerpt box to your page editor</h2>
<p>The first thing you should do is open your theme&#8217;s <code>functions.php</code> file in your favorite text editor.  Paste the following <acronym title="Hypertext Preprocessor">PHP</acronym> code into it:</p>
<pre><code>add_action( 'admin_menu', 'my_page_excerpt_meta_box' );

function my_page_excerpt_meta_box() {
	add_meta_box( 'postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'page', 'normal', 'core' );
}</code></pre>
<p>Now, you&#8217;ll be able to add excerpts to your pages, just like posts.  This can come in handy with themes that display search results in excerpt form.</p>
<h2>Adding custom taxonomies to your page editor</h2>
<p>This one will be a bit trickier.  I&#8217;ll have to assume you&#8217;ve created a custom taxonomy specifically for pages.  If you&#8217;re unfamiliar with this process, you need to familiarize yourself with <a href="http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28" title="Custom taxonomies in WordPress 2.8">creating custom taxonomies</a>.</p>
<p>Let&#8217;s assume you&#8217;ve created a &#8220;People&#8221; taxonomy for pages.  Your custom taxonomy code should look a little like this.  </p>
<pre><code>register_taxonomy( 'people', 'page', array( 'hierarchical' => false, 'label' => 'People', 'query_var' => true, 'rewrite' => true ) );</code></pre>
<p>The important thing in that line is <code>page</code>.  We&#8217;ll be adding meta boxes for all taxonomies that have been registered for pages.</p>
<p>Again, we&#8217;ll go to our theme&#8217;s <code>functions.php</code> file.  Paste this <acronym title="Hypertext Preprocessor">PHP</acronym> code in:</p>
<pre><code>add_action( 'admin_menu', 'my_page_taxonomy_meta_boxes' );

function my_page_taxonomy_meta_boxes() {
	foreach ( get_object_taxonomies( 'page' ) as $tax_name ) {
		if ( !is_taxonomy_hierarchical( $tax_name ) ) {
			$tax = get_taxonomy( $tax_name );
			add_meta_box( "tagsdiv-{$tax_name}", $tax->label, 'post_tags_meta_box', 'page', 'side', 'core' );
		}
	}
}</code></pre>
<p>Once that&#8217;s done, you&#8217;ll be able to use your page-based custom taxonomies.</p>
<p class="note">Please note that hierarchical taxonomies aren&#8217;t going to be available yet.  Maybe in WordPress 3.0?</p>
<h2>A good move by WordPress</h2>
<p>I&#8217;m glad WordPress is moving in this direction with some of its functionality.  Average Joe might not realize the implications of something as simple as moving code to another file, but developers should rejoice.  The reuse of code is a cornerstone of good development practice.  By making things more modular, it becomes easier to create new things without rewriting a lot of code.</p>
<p>I&#8217;ve shown you how to do these things with pages.  Just imagine being able to make these simple and quick changes for custom post types (i.e., content types), essentially having the ability to create any type of site you want with WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/11/09/excerpts-and-taxonomies-for-pages-in-wordpress-2-9/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Custom capabilities in plugins and themes</title>
		<link>http://justintadlock.com/archives/2009/09/18/custom-capabilities-in-plugins-and-themes</link>
		<comments>http://justintadlock.com/archives/2009/09/18/custom-capabilities-in-plugins-and-themes#comments</comments>
		<pubDate>Sat, 19 Sep 2009 02:33:50 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1821</guid>
		<description><![CDATA[How to make your WordPress plugin or theme more flexible by allowing users to select who has access to its settings page(s).]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span> can probably list a million reasons I think my recent <a href="http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin" title="Members: WordPress plugin">Members plugin</a> is neat.  Not only have I deployed it on about five of my own blogs in the last few days, I&#8217;ve also started integrating it with some of my other plugins and themes.</p>
<p>One of the features I feel that&#8217;s lacking in most plugins and themes is the ability to define custom capabilities to access certain content.  This is one of the reasons I&#8217;ve developed this plugin.</p>
<p>If you&#8217;re a plugin or theme developer and add admin menus, this tutorial should be helpful.  What I&#8217;ll be showing you is a way to give users of your plugin <em>smarter</em> control over its settings.</p>
<h2>Adding an admin menu page the normal way</h2>
<p>There are several functions for adding <a href="http://codex.wordpress.org/Adding_Administration_Menus" title="Adding administration menus">admin menus</a>, which all work basically the same way.  I&#8217;ll use <code>add_submenu_page()</code> as an example since it&#8217;s fairly common.</p>
<p>When adding a page, you&#8217;ll use the function like this:</p>
<pre><code>add_submenu_page( $parent_page, $page_title, $menu_title, $capability, $file, $function );</code></pre>
<p>What we&#8217;ll be focusing on here is the <code>$capability</code> variable.  Typically, this is hardcoded, but we need to be able to change this.  So, when writing that code, you should replace <code>$capability</code> with a filter hook:</p>
<pre><code>add_submenu_page( $parent_page, $page_title, $menu_title, apply_filters( 'plugin_name_capability', $capability ), $file, $function );</code></pre>
<p><code>plugin_name_capability</code> should be something unique to your plugin.  Just leave <code>$capability</code> as  whatever capability you would normally use.  It can now be changed.</p>
<p>Making this change does two important things:</p>
<ol>
<li>Allows users to change the capability if they want to with a filter.</li>
<li>Allows you to integrate your plugin with the <em>Members</em> plugin.</li>
</ol>
<p>You can stop reading here and will have done your part in making your plugin more flexible.  However, you can offer integration with my <em>Members</em> plugin, which will make it even easier for users to use.</p>
<h2>Integrating your plugin/theme with the Members plugin</h2>
<p>Here&#8217;s where the real neat stuff comes into play.  You can run a check to see if the <em>Members</em> plugin is installed.  If the plugin is indeed installed, you can create a custom capability just for your plugin&#8217;s settings page.</p>
<p>Let&#8217;s assume that filter hook was something like this:</p>
<pre><code>apply_filters( 'plugin_name_capability', 'manage_options' );</code></pre>
<p>People without the <em>Members</em> plugin would need the <code>manage_options</code> capability to change the settings for your plugin.  To me, that doesn&#8217;t sound like a great solution, and it definitely doesn&#8217;t offer the site owner much flexibility.</p>
<p>If the <em>Members</em> plugin is installed, we&#8217;ll change that capability to something like <code>edit_my_plugin_settings</code> (change to something unique):</p>
<pre><code>if ( function_exists( 'members_plugin_init' ) )
	add_filter( 'plugin_name_capability', 'plugin_name_unique_capability' );

function plugin_name_unique_capability( $cap ) {
	return 'edit_my_plugin_settings';
}</code></pre>
<p>Now, only users of a role with the <code>edit_my_plugin_settings</code> capability will be able to access that plugin&#8217;s page.</p>
<h2>Adding the capability to the role edit page</h2>
<p>You can offer even more integration with the <em>Members</em> plugin if you like.  You can add a checkbox to the <em>Edit Role</em> page that allows users to easily select this capability rather than typing it in.</p>
<pre><code>if ( function_exists( 'members_get_capabilities' ) )
	add_filter( 'members_get_capabilities', 'plugin_name_extra_caps' );

function plugin_name_extra_caps( $caps ) {
	$caps[] = 'edit_my_plugin_settings';
	return $caps;
}</code></pre>
<h2>Why is all this important?</h2>
<p>Imagine running a site with 20 different writers, publishers, administrators, and so on.  Some people of that site need specific access to certain things but no access to other things.</p>
<p>For example, a friend and I are both running this site with all these people.  The friend doesn&#8217;t need access to the WordPress options, but he does need access to your plugin&#8217;s options.  Those should be controlled by two separate capabilities rather than one.</p>
<p>I created <em>Members</em> to allow site owners to have as much flexibility as possible.  But, the plugin itself can only do so much on its own.  As developers in the WordPress community, we can make WordPress infinitely flexible by working together, and I&#8217;m definitely trying to make it as easy as possible to integrate other plugins with my own.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/09/18/custom-capabilities-in-plugins-and-themes/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Adding and using custom user profile fields</title>
		<link>http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields</link>
		<comments>http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields#comments</comments>
		<pubDate>Fri, 11 Sep 2009 04:40:09 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1796</guid>
		<description><![CDATA[How to create and display custom user profile fields in WordPress that allow users to input additional information about themselves.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">S</span>ince I&#8217;ve been playing around with user management a lot lately, I thought I&#8217;d share a simple technique I picked up.  This technique will allow you to easily add new user profile fields that your blog&#8217;s users can use to input more information about themselves.</p>
<p>Management of these fields will be coming in a later version of my user management plugin, but some of you may want to do this now.</p>
<p>In this tutorial, I&#8217;ll show you how to add an input box for a Twitter username and how to display it on your site, which will look a little something like this:</p>
<div id="attachment_1797" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/09/pop-critics-profile.png" alt="My profile and Twitter link" title="Twitter link" width="600" height="145" class="size-full wp-image-1797" /><p class="wp-caption-text">My profile and Twitter link</p></div>
<p>If you want to see a live example, check out <a href="http://popcritics.com/2009/09/the-cw-adds-the-vampire-diaries-to-its-supernatural-lineup" title="Pop Critics: The CS adds the Vampire Diaries to its supernatural lineup">one of my latests posts</a> on Pop Critics.</p>
<h2>Adding custom user fields</h2>
<p>Open your theme&#8217;s <code>functions.php</code> file and drop this <acronym title="Hypertext Preprocessor">PHP</acronym> code in:</p>
<pre class="php"><code>add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) { ?>

	&lt;h3>Extra profile information&lt;/h3>

	&lt;table class="form-table">

		&lt;tr>
			&lt;th>&lt;label for="twitter">Twitter&lt;/label>&lt;/th>

			&lt;td>
				&lt;input type="text" name="twitter" id="twitter" value="&lt;?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" />&lt;br />
				&lt;span class="description">Please enter your Twitter username.&lt;/span>
			&lt;/td>
		&lt;/tr>

	&lt;/table>
&lt;?php }</code></pre>
<p>This will create a new area in the user edit screen that looks like this:</p>
<div id="attachment_1798" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/09/extra-fields.png" alt="Additional profile fields" title="Profile fields" width="600" height="151" class="size-full wp-image-1798" /><p class="wp-caption-text">Additional profile fields</p></div>
<p>The custom part of the code is this bit:</p>
<pre><code>&lt;tr>
	&lt;th>&lt;label for="twitter">Twitter&lt;/label>&lt;/th>

	&lt;td>
		&lt;input type="text" name="twitter" id="twitter" value="&lt;?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" />&lt;br />
		&lt;span class="description">Please enter your Twitter username.&lt;/span>
	&lt;/td>
&lt;/tr></code></pre>
<p>Note that if you want to add more fields, copy that and change <code>twitter</code> to something unique for each additional field.  Just make sure you change each instance of <code>twitter</code>.</p>
<h2>Saving the custom user fields</h2>
<p>Just because we&#8217;re displaying these extra fields, doesn&#8217;t mean they&#8217;ll be saved when the user profile is updated.  So, we need one more function to handle this.  Drop this <acronym title="Hypertext Preprocessor">PHP</acronym> code in your theme&#8217;s <code>functions.php</code> file.</p>
<pre><code>add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

	if ( !current_user_can( 'edit_user', $user_id ) )
		return false;

	/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
	update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
}</code></pre>
<p>Now, your information will be saved.</p>
<h2>Displaying custom user fields on the site</h2>
<p>For getting these additional fields, WordPress has two nifty functions: <code>the_author_meta()</code> and <code>get_the_author_meta()</code>.  The former displays the meta information, and the latter returns it for use in <acronym title="Hypertext Preprocessor">PHP</acronym>.  Each takes in two parameters:</p>
<pre><code>the_author_meta( $meta_key, $user_id );</code></pre>
<p>You can use this to grab the information from any of the fields you&#8217;ve created.  For example, the <code>$meta_key</code> for our Twitter field is <code>twitter</code>.  We just need to call it up somewhere in our theme.</p>
<p>So, what we&#8217;re going to do is build an author box to add to the end of our single posts.  Once again, we visit our theme&#8217;s <code>functions.php</code> file and drop some <acronym title="Hypertext Preprocessor">PHP</acronym> code in:</p>
<pre><code>function my_author_box() { ?>
	&lt;div class="author-profile vcard">
		&lt;?php echo get_avatar( get_the_author_meta( 'user_email' ), '96' ); ?>

		&lt;h4 class="author-name fn n">Article written by &lt;?php the_author_posts_link(); ?>&lt;/h4>

		&lt;p class="author-description author-bio">
			&lt;?php the_author_meta( 'description' ); ?>
		&lt;/p>

		&lt;?php if ( get_the_author_meta( 'twitter' ) ) { ?>
			&lt;p class="twitter clear">
				&lt;a href="http://twitter.com/&lt;?php the_author_meta( 'twitter' ); ?>" title="Follow &lt;?php the_author_meta( 'display_name' ); ?> on Twitter">Follow &lt;?php the_author_meta( 'display_name' ); ?> on Twitter&lt;/a>
			&lt;/p>
		&lt;?php } // End check for twitter ?>
	&lt;/div>&lt;?php
}</code></pre>
<p>Now, all you need to do call the function in your theme&#8217;s <code>single.php</code> file somewhere after the post has been displayed:</p>
<pre><code>&lt;?php my_author_box(); ?></code></pre>
<p>If you&#8217;re using a child theme, your theme author can probably tell you a more appropriate action hook to add this function to so you don&#8217;t mess up your theme&#8217;s template files.</p>
<h2>What other custom user field uses can you think of?</h2>
<p>This is just another one of those powerful features of WordPress that I don&#8217;t see used much.  I have several things in mind that I could use this technique for, but I&#8217;d like to hear what you&#8217;d do with it.</p>
<p>Surely we can do some cooler stuff than just displaying a link to Twitter?</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields/feed</wfw:commentRss>
		<slash:comments>82</slash:comments>
		</item>
		<item>
		<title>How to disable scripts and styles</title>
		<link>http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles</link>
		<comments>http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles#comments</comments>
		<pubDate>Thu, 06 Aug 2009 07:08:57 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1773</guid>
		<description><![CDATA[Does using multiple WordPress plugins load so many files to your site that it becomes unbearably slow?  If so, you can easily disable scripts and styles and load them only when needed.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">M</span>any plugins and themes add JavaScript and <acronym title="Cascading Style Sheets">CSS</acronym> files to your site.  While this alone isn&#8217;t necessarily a bad thing, using several plugins that do this can bog down your site with loads of requests for these files.  </p>
<p>The good news is that WordPress has a built-in system that allows us to deregister these scripts and styles.</p>
<p><em>Wait, don&#8217;t the plugins require this code?</em>  Probably.  But, we want to take control of these files and make our sites run faster.  Disabling these scripts and styles will allow us to do a few things:</p>
<ol>
<li>Combine multiple files into single files (mileage may vary with JavaScript here).</li>
<li>Load the files only on the pages we&#8217;re using the script or style.</li>
<li>Stop having to use <code>!important</code> in our <code>style.css</code> file to make simple <acronym title="Cascading Style Sheets">CSS</acronym> adjustments.</li>
</ol>
<p>For this exercise, I&#8217;ve chosen two popular plugins from the plugin repository:  <a href="http://wordpress.org/extend/plugins/contact-form-7/" title="Contact Form 7">Contact Form 7</a> and <a href="http://wordpress.org/extend/plugins/wp-pagenavi/" title="WP-PageNavi">WP-PageNavi</a>.</p>
<h2>The dirty truth</h2>
<p>Not all plugins use the appropriate methods for loading scripts and styles.  Some developers just drop stuff right in the header.  This is usually because they&#8217;re not familar with two important WordPress functions: <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script" title="WordPress Codex: wp_enqueue_script()">wp_enqueue_script()</a> and <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_style" title="WordPress Codex: wp_enqueue_style()">wp_enqueue_style()</a>.  If your plugin/theme author isn&#8217;t using these functions, please encourage them to do so.  It allows the rest of us to work with their code using the methods WordPress provides.</p>
<p>While figuring out what scripts or styles you want to disable, you might have to get your hands dirty.  This means looking in code.  Unless your plugin author has documented the script or style <code>handle</code>, you&#8217;ll need to find it.</p>
<h2>Disabling JavaScript</h2>
<p>For this example, we&#8217;ll be disabling the <em>Contact Form 7</em> plugin&#8217;s JavaScript.  The first thing you need to do is find the <code>handle</code> for the script.  Open the <code>wp-contact-form-7.php</code> file in your favorite text editor and do a search for <code>wp_enqueue_script</code>.  Doing so will turn up this bit of code:</p>
<pre><code>wp_enqueue_script( 'contact-form-7', wpcf7_plugin_url( 'contact-form-7.js' ), array('jquery', 'jquery-form'), WPCF7_VERSION, $in_footer );</code></pre>
<p>The <code>handle</code> for this plugin&#8217;s JavaScript is <code>contact-form-7</code>.  Now, you can close this file and move on.</p>
<p>Open your theme&#8217;s <code>functions.php</code> file and add this <acronym title="Hypertext Preprocessor">PHP</acronym> in:</p>
<pre><code>add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
	wp_deregister_script( 'contact-form-7' );
}</code></pre>
<p>Once saved, the script will no longer load.  You can deregister as many scripts as you want within this function.</p>
<h2>Disabling styles</h2>
<p>In this example, we&#8217;ll be disabling <em>WP-PageNavi&#8217;s</em> stylesheet.  This is something I almost always do because I add the style rules to my theme&#8217;s <code>style.css</code> file.</p>
<p>The first thing you should do is open <code>wp-pagenavi.php</code> in a text editor and search for <code>wp_enqueue_style</code>.  This will turn up this code:</p>
<pre><code>wp_enqueue_style('wp-pagenavi', get_stylesheet_directory_uri().'/pagenavi-css.css', false, '2.50', 'all');</code></pre>
<p>And this:</p>
<pre><code>wp_enqueue_style('wp-pagenavi', plugins_url('wp-pagenavi/pagenavi-css.css'), false, '2.50', 'all');</code></pre>
<p>What we&#8217;re looking for is <code>wp-pagenavi</code>, which is the <code>handle</code> for the style.  Once you&#8217;ve found that, close the file and add this to your theme&#8217;s <code>functions.php</code> file.</p>
<pre><code>add_action( 'wp_print_styles', 'my_deregister_styles', 100 );

function my_deregister_styles() {
	wp_deregister_style( 'wp-pagenavi' );
}</code></pre>
<p>That&#8217;ll disable the stylesheet for this plugin.  Feel free to deregister as many styles as you want within this function.</p>
<h2>Tips on making this work better</h2>
<p>You&#8217;ve disabled several scripts and styles, but you need to do something with them.  Here&#8217;s a list of tips on how to make use of the methods described in this tutorial:</p>
<ul>
<li>Append styles that you&#8217;ve disabled to the end of your theme&#8217;s <code>style.css</code> file and edit them from there to get the look you want.</li>
<li>Combine several scripts into a single file and load it yourself.  I would only do this for things that use the same JavaScript library.  For example, I often combine scripts that are built on jQuery.</li>
<li>Use <a href="http://codex.wordpress.org/Conditional_Tags" title="WordPress Codex: Conditional Tags">conditional tags</a> for fine-grained control over when a script or style is loaded.</li>
</ul>
<p>If you disable something, it may cause the plugin/theme not to work correctly.  Most styles can easily be added to your theme&#8217;s stylesheet so that you&#8217;re not loading a ton of stylesheets on your site.  JavaScript is a different beast altogether, and I only recommend combining multiple files into one if you know what you&#8217;re doing.</p>
<p>Have fun with this.  Experiment.  Share your experience with others in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles/feed</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>Contextually changing your theme&#8217;s stylesheet</title>
		<link>http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet</link>
		<comments>http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet#comments</comments>
		<pubDate>Tue, 28 Jul 2009 03:49:54 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1767</guid>
		<description><![CDATA[How to dynamically load different stylesheets when you need to drastically alter the style of specific pages on your WordPress-powered site.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">W</span>ordPress 2.8 introduced the <code>body_class()</code> function, which allows you to contextually style elements in your theme&#8217;s <code>style.css</code>.  Few themes allowed this sort of functionality before this release.  </p>
<p>While it&#8217;s cool to be able to style a particular post or page (or tons of other things) with a simple <acronym title="Cascading Style Sheets">CSS</acronym> selector in a single stylesheet, it&#8217;s not always enough.  Sometimes, you may need to drastically change the appearance of a page.  To do this, you&#8217;d need to load a different stylesheet.</p>
<p>Many tutorials will tell you to dive directly into your theme&#8217;s <code>header.php</code> file.  Of course, you know I&#8217;m more interested in doing things the <em>smart</em> way by taking advantage of a theme&#8217;s <code>functions.php</code> file.  This technique will allow you to easily transfer your custom code from theme to theme, use within a plugin, and it&#8217;s the best method when working from a child theme.</p>
<h2>Dynamically changing your theme&#8217;s stylesheet</h2>
<p>For this example, we have two pages we want use separate stylesheets on:  About and Portfolio.  The first thing you should do is create your stylesheets.  Drop them into your theme (or child theme) folder and name them <code>style-about.css</code> and <code>style-portfolio.css</code>.</p>
<p>Once that&#8217;s done, add this code to your <code>functions.php</code> file:</p>
<pre><code>&lt;?php

add_filter( 'stylesheet_uri', 'my_stylesheet', 10, 2 );

function my_stylesheet( $stylesheet_uri, $stylesheet_dir_uri ) {

	if ( is_page( 'about' ) )
		$stylesheet_uri = $stylesheet_dir_uri . '/style-about.css';
	elseif ( is_page( 'portfolio' ) )
		$stylesheet_uri = $stylesheet_dir_uri . '/style-portfolio.css';

	return $stylesheet_uri;
}

?></code></pre>
<p>Just save and check out your new styles.</p>
<h2>The code explained</h2>
<p>What we&#8217;ve done with the few lines of code above is filter <code>stylesheet_uri</code>, which is a hook that returns your currently active theme&#8217;s stylesheet.  This hook gives us two parameters we can use:</p>
<ul>
<li><code>$stylesheet_uri</code><br />
	The <acronym title="Uniform Resource Identifier">URI</acronym> to the current theme&#8217;s stylesheet, which needs to be returned.</li>
<li><code>$stylesheet_dir_uri</code><br />
	The <acronym title="Uniform Resource Identifier">URI</acronym> of the current theme&#8217;s directory, which we can use in our own function and not have to figure out where our styleheets are.</li>
</ul>
<p>The <code>is_page()</code> function is one of many <a href="http://codex.wordpress.org/Conditional_Tags" title="WordPress Codex: Conditional Tags">conditional tags</a> at your disposal for determining what page a visitor is currently viewing.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>How to filter a WordPress theme&#8217;s &#8216;more link&#8217; text</title>
		<link>http://justintadlock.com/archives/2009/07/01/how-to-filter-a-wordpress-themes-more-link-text</link>
		<comments>http://justintadlock.com/archives/2009/07/01/how-to-filter-a-wordpress-themes-more-link-text#comments</comments>
		<pubDate>Thu, 02 Jul 2009 03:10:40 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1737</guid>
		<description><![CDATA[A tutorial on how to create custom more link text for your WordPress theme using <code>the_content_more_link</code> filter hook.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">C</span>hanging the <em>more link</em> in a WordPress theme is easy.  Just open your theme files and change it.  But, if you&#8217;re writing a plugin to change this or want to preserve your theme&#8217;s code (e.g., child themes), you need a way to easily edit this.</p>
<p>I&#8217;ve seen some themes add their own more link filter hook, but this is unnecessary because WordPress 2.8 introduced <code>the_content_more_link</code> filter hook.  Maybe this post will help those theme authors cut back on an extra filter hook when it&#8217;s not needed.</p>
<p>This will allow us to easily overwrite the default.</p>
<h2>What is the more link?</h2>
<p>When writing a WordPress post, you can cut the text off at any point by adding in this code:</p>
<pre><code>&lt;!--more--></code></pre>
<p>If you&#8217;re using a theme that shows the standard full post on the home/blog page of your site, this will cut the article short at the point you added the code.  It will also add a link to the single-post view where the reader can continue reading the post.</p>
<h2>Using the_content_more_link filter hook</h2>
<p>What we want to do is change our theme&#8217;s more link text, but we need to do this the appropriate way, and the appropriate way means not hacking up your theme author&#8217;s code.</p>
<p>Let&#8217;s assume our theme&#8217;s more link outputs &#8220;(more&#8230;)&#8221; when we add the <code>&lt;!--more--></code> link within the post editor.  Maybe we don&#8217;t like that message too much.  We&#8217;d like to change it to read &#8220;Continue reading &rarr;&#8221; instead.</p>
<p>Open your theme&#8217;s (or child theme&#8217;s) <code>functions.php</code> file and paste this code in:</p>
<pre><code>&lt;?php

add_filter( 'the_content_more_link', 'my_more_link', 10, 2 );

function my_more_link( $more_link, $more_link_text ) {
	return str_replace( $more_link_text, 'Continue reading &amp;rarr;', $more_link );
}

?></code></pre>
<p>That&#8217;s all there is to it.  Enjoy your custom more link text.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/07/01/how-to-filter-a-wordpress-themes-more-link-text/feed</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Showing the post password form for excerpts in WordPress</title>
		<link>http://justintadlock.com/archives/2009/06/24/showing-the-post-password-form-for-excerpts-in-wordpress</link>
		<comments>http://justintadlock.com/archives/2009/06/24/showing-the-post-password-form-for-excerpts-in-wordpress#comments</comments>
		<pubDate>Wed, 24 Jun 2009 08:22:49 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1721</guid>
		<description><![CDATA[How to replace excerpts for password-protected posts in WordPress with a password form instead of the standard no excerpt message.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span> recently came across an interesting situation that I had never thought about before.  Many WordPress themes show excerpts on the front page and other archive-type views.  When viewing a password-protected post, this message is displayed:</p>
<blockquote><p>
There is no excerpt because this is a protected post.
</p></blockquote>
<p>While this is fine for many scenarios, it may not be the most helpful piece of text for the average Internet user.  Instead of showing the message, we&#8217;ll replace it with a password form.</p>
<h2>Replacing the no excerpt text with a password form</h2>
<p>WordPress comes packaged with a neat function called <code>get_the_password_form()</code> that handles most of the work for us.  It generates the entire form.  All we need to do is load it at the appropriate time.</p>
<p>Open your theme&#8217;s <code>functions.php</code> file and drop this code in:</p>
<pre><code>&lt;?php

add_filter( 'the_excerpt', 'excerpt_protected' );

function excerpt_protected( $content ) {
	if ( post_password_required() )
		$content = get_the_password_form();

	return $content;
}

?></code></pre>
<p>This will give us a new message:</p>
<blockquote><p>
This post is password protected. To view it please enter your password below:
</p></blockquote>
<p>Followed by that message is an input field for the post password.</p>
<h2>Writing shorter tutorials</h2>
<p>For those of you that follow this blog regularly, you know that I typically write long, in-depth tutorials.  Many times, these are advanced techniques that not everyone will use.  My plan is to start mixing in some quick tutorials that only take a few minutes to implement and maybe help out the average user more.  This way, I can write more often.  The longer tutorials tend to take a few days of work.</p>
<p>If you have any ideas for WordPress or bbPress tutorials, feel free to let me know in the comments or through my <a href="http://justintadlock.com/contact" title="Contact page">contact form</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/06/24/showing-the-post-password-form-for-excerpts-in-wordpress/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
