<?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; functions</title>
	<atom:link href="http://digwp.com/tag/functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Fri, 18 May 2012 18:21:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Don&#8217;t fork your theme, flex it with &#8220;is_plugin_active&#8221; conditional</title>
		<link>http://digwp.com/2012/04/dont-fork-your-theme-flex-it-with-is_plugin_active-conditional/</link>
		<comments>http://digwp.com/2012/04/dont-fork-your-theme-flex-it-with-is_plugin_active-conditional/#comments</comments>
		<pubDate>Wed, 04 Apr 2012 17:49:08 +0000</pubDate>
		<dc:creator>Peter Shackelford</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[multisite]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=5847</guid>
		<description><![CDATA[Donkey Work Donkey work is really the last thing I want to be doing. Piddly tasks that could have been avoided with a little thought and perspective. Below I explain how I worked my way away from becoming a donkey with a dozen child themes to manage and maintain, with just a little knowledge of [...]]]></description>
			<content:encoded><![CDATA[<h3>Donkey Work</h3>
<p>Donkey work is really the last thing I want to be doing. Piddly tasks that could have been avoided with a little thought and perspective. Below I explain how I worked my way <em>away</em> from becoming a donkey with a dozen child themes to manage and maintain, with just a little knowledge of a native wordpress function.</p>
<p><span id="more-5847"></span></p>
<h3>The details.</h3>
<p>I am running a multisite that predominately uses a single child theme. Each site has it&#8217;s separate color scheme applied through a few lines of css. Where sites need unique functionality, <a href="http://wpcandy.com/teaches/how-to-create-a-functionality-plugin" title="functionality plugin" target="_blank">functionality plugins</a> are used. These contain custom post types, rss redirects, custom thumbnail sizes etc… This has worked really well for keeping our theme&#8217;s function.php file slim while giving us all the functionality we need, where we need it.</p>
<p>Each site uses a single identical footer, which is built into the theme. At the time, we did this knowing that we would be creating department sites as subdirectories. Content between the utility navigation and the footer was to be their turf but the utility nab and footer content are locked down. We built our universal footer using switch_to_blog function and a custom menu.</p>
<pre><code>&lt;?php
	global $blog_id;
		global $current_blog;
		switch_to_blog(25);
        	$args = array(
			'container'    =&gt; 'div',
			'menu'         =&gt; 'Footer',
			'container_id' =&gt; 'footer-links',
			'menu_class'   =&gt; 'menu', 
			'echo'         =&gt; true,
			'fallback_cb'  =&gt; 'wp_page_menu',
			'depth'        =&gt; 0
		);
		wp_nav_menu($args);
		restore_current_blog(); ?&gt;
		
&lt;div class="fix"&gt;&lt;/div&gt;
&lt;script type="text/javascript"&gt;
jQuery(document).ready(function() {
	jQuery("ul#menu-footer.menu &gt; li &gt; a").contents().unwrap();
	jQuery('input[type=text]').focus(function() {
		jQuery(this).val('');
	});
});
&lt;/script&gt;</code></pre>
<p>The above code registers a new menu area called Footer. To take advantage of this I need to create a menu in the wordpress menu area with that exact name. The bit of JQuery turns off the link in the first level of menu items. This with a little css is used to create the menu headers. Great! One identical footer that is used on every site that uses this child theme. </p>
<h3>The Dilemma</h3>
<p>Recently we offered to host/manage websites for regional offices in our organization. They would benefit from our existing infrastructure and consistent branding but all of the content and navigation would be their own. They would not need our built in footer, at least not as it is on all the other sites.</p>
<p>I considered having a separate theme that was modified just for regional offices, I also considered building a plugin that disabled and replaced the footer on the existing theme. The first option would not be sustainable in the long run, the second very complicated at the outset. To be honest I very much doubt I could have pulled it off. My solution was to take advantage of the fact that I had already created a functionality plugin that would be used on every regional site. Using the <a href="http://codex.wordpress.org/Function_Reference/is_plugin_active" title="is_plugin_active">is_plugin_active</a> conditional I was able to alter the theme to not switch_to_blog if the regional plugin was enabled. </p>
<pre><code>if (is_plugin_active('regional-functionality-plugin.php')) {
	//plugin is activated! Look no switch_to_blog!!
	$args = array(
		'container'    =&gt; 'div',
		'menu'         =&gt; 'Footer',
		'container_id' =&gt; 'footer-links',
		'menu_class'   =&gt; 'menu', 
		'echo'         =&gt; true,
		'fallback_cb'  =&gt; 'wp_page_menu',
		'depth'        =&gt; 0
	);
	wp_nav_menu($args);
} else {
	global $blog_id;
	global $current_blog;
	switch_to_blog(45);
	$args = array(
		'container'    =&gt; 'div',
		'menu'         =&gt; 'Footer',
		'container_id' =&gt; 'footer-links',
		'menu_class'   =&gt; 'menu', 
		'echo'         =&gt; true,
		'fallback_cb'  =&gt; 'wp_page_menu',
		'depth'        =&gt; 0
	);
	wp_nav_menu($args);
	restore_current_blog();
} ?&gt;</code></pre>
<p>There we have it, 12 lines of code for the love of a single maintainable theme. So, if you want to earn your salt as a WordPress Developer, learn your <a href="http://codex.wordpress.org/Function_Reference/" title="WP Functions">functions</a> and save your energy for the creative work.</p>
<h3>About the Author</h3>
<p>Peter builds web platforms based on WordPress. In his off time he is expounding on the wonders of WordPress among family, friends and strangers. He and his brother host a monthly WordPress meetup in Jackson Michigan.</p>
<hr />
<p><small>© 2012 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2012/04/dont-fork-your-theme-flex-it-with-is_plugin_active-conditional/">Permalink</a> | <a href="http://digwp.com/2012/04/dont-fork-your-theme-flex-it-with-is_plugin_active-conditional/#comments">3 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2012/04/dont-fork-your-theme-flex-it-with-is_plugin_active-conditional/&title=Don&#8217;t fork your theme, flex it with &#8220;is_plugin_active&#8221; conditional">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/multisite/" rel="tag">multisite</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2012/04/dont-fork-your-theme-flex-it-with-is_plugin_active-conditional/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting Comment Info from the WordPress Database</title>
		<link>http://digwp.com/2012/03/getting-comment-info-wordpress-database/</link>
		<comments>http://digwp.com/2012/03/getting-comment-info-wordpress-database/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 17:16:45 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=5861</guid>
		<description><![CDATA[An easy way for visitors to enter their emails is by commenting on a post. We did this recently for people to sign up for a notification email. Instead of using a plugin or custom function for a one-time email list, we just went with WordPress core functionality and used post comments for people to [...]]]></description>
			<content:encoded><![CDATA[<p>An easy way for visitors to enter their emails is by commenting on a post. We did this recently for people to <a href="http://digwp.com/2012/02/notification-list-3-3-printed-books/">sign up for a notification email</a>. Instead of using a plugin or custom function for a one-time email list, we just went with WordPress core functionality and used post comments for people to sign up. Then the trick then is retrieving the comment information from the database for the specific sign-up post. </p>
<p>We did this recently to collect commentators&#8217; email addresses, but could have easily extracted other comment info as well &mdash; comment author, comment date, comment url, and basically anything in the <code>wp_comments</code> table, shown here:</p>
<p><span id="more-5861"></span></p>
<div class="post-box-201203"><img src="http://digwp.com/wp-content/uploads/2012/03/getting-comment-info.jpg" alt="getting-comment-info" width="245" height="428" /><br /><em>columns in the <code>wp_comments</code> table</em></div>
<p>You can easily display and collect any of this information for any specific page or post on your site. All you need is a non-public page (or other theme location) to output the results (&#8220;non-public&#8221; especially if you&#8217;re displaying any email data). In our case we just created a new private page and selected our custom page template. Load the page and <em>viola!</em> &mdash; instant list of all comment author emails for our sign-up post.</p>
<h3>Getting comment info from the database</h3>
<p>So you&#8217;ve got your sign-up post with some comments, and now want to collect the information and send some emails or whatever. To get the information, we need to query the WP database, select our columns from the <code>wp_comments</code> table, and then display the results on our custom page. </p>
<p>For the SQL query, getting data from the comment table is straightforward, but doing so for a <em>specific post</em> requires a dash of voodoo found in an update on <a href="http://webtrickz.com/how-to-extract-commentators-email-address-with-ip-name-from-a-post-in-wordpress-featured/" title="How to Extract commentators Email address with IP &#038; Name from a post in WordPress">this post</a>. To make a long story short, you have to use nested queries with an arbitrary &#8220;AS WHATEVER&#8221; added at the end, as such:</p>
<pre><code>SELECT DISTINCT comment_author, comment_author_email, comment_author_IP 
FROM ( 
SELECT DISTINCT comment_author, comment_author_email, comment_author_IP 
FROM wp_comments WHERE comment_post_ID = 1
) AS WHATEVER</code></pre>
<p>The &#8220;WHATEVER&#8221; is essentially meaningless, so use any name you want. Why? Apparently the &#8220;AS&#8221; clause is required for the nested (or whatever) queries to work their magic. As you can see, this enables us to grab <em>any column</em> from the <code>wp_comments</code> table. In the example query, we&#8217;re selecting the <code>comment_author</code>, <code>comment_author_email</code>, and <code>comment_author_IP</code> columns.</p>
<p>If you have access to the database, you can use a program such as <a href="http://www.phpmyadmin.net/">phpMyAdmin</a> to execute the above query directly. Otherwise, we&#8217;ll go with the WordPress custom-private-page route. Open your page template and add the following code beneath <code>the_content()</code> template tag:</p>
<pre><code>&lt;?php //grab the data
$comment_info = $wpdb-&gt;get_results("SELECT DISTINCT comment_author, comment_author_email, comment_author_IP 
	FROM (SELECT DISTINCT comment_author, comment_author_email, comment_author_IP 
	FROM wp_comments 
	WHERE comment_post_ID = 1
	) AS WHATEVER"); 
// display the results
echo '&lt;ul&gt;';
foreach($comment_info as $info) { 
	echo '&lt;li&gt;&lt;strong&gt;'. $info-&gt;comment_author .'&lt;/strong&gt; - '. $info-&gt;comment_author_email .' - &lt;small&gt;'. $info-&gt;comment_author_IP .'&lt;/small&gt;&lt;/li&gt;'; 
}
echo '&lt;/ul&gt;';
?&gt;</code></pre>
<p>Just pick your post ID and done. When you visit the custom page in a browser, you should see the results of your query displayed as a list, similar to this:</p>
<ul>
<li><strong>Juan Gris</strong> &#8211; <code>juan@hotmail.com</code> &#8211; <small>123.456.789</small></li>
<li><strong>Max Ernst</strong> &#8211; <code>max@gmail.com</code> &#8211; <small>987.654.321</small></li>
<li><strong>Salvador Dali</strong> &#8211; <code>dali@email.com</code> &#8211; <small>456.789.123</small></li>
</ul>
<p>But no need to keep it list format, with a little tweaking, we can output any data using whatever markup works best. For example, to just grab the emails from a nice <code>&lt;pre&gt;</code> list, change the <code>foreach</code> loop to this:</p>
<pre><code>echo '&lt;pre&gt;';
foreach($comment_info as $info) { 
	echo $info-&gt;comment_author_email . "\n";
}
echo '&lt;/pre&gt;';</code></pre>
<p>..and that should give you just the data, with no interfering markup:</p>
<pre><code>juan@hotmail.com
max@gmail.com
dali@email.com</code></pre>
<h3>Customizing</h3>
<p>There are two ways to customize this technique. In the query itself, you can specify which columns you want to display. And then you can also customize the markup, to format the data to suit your specific needs. Sort of a <em>multipurpose</em> method for grabbing post-specific info from the database.</p>
<hr />
<p><small>© 2012 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2012/03/getting-comment-info-wordpress-database/">Permalink</a> | <a href="http://digwp.com/2012/03/getting-comment-info-wordpress-database/#comments">5 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2012/03/getting-comment-info-wordpress-database/&title=Getting Comment Info from the WordPress Database">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/comments/" rel="tag">comments</a>, <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/sql/" rel="tag">sql</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2012/03/getting-comment-info-wordpress-database/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Displaying Theme Data with WordPress</title>
		<link>http://digwp.com/2011/12/displaying-theme-data-with-wordpress/</link>
		<comments>http://digwp.com/2011/12/displaying-theme-data-with-wordpress/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 18:36:29 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

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

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

    $theme_name = 'twentyeleven'; 

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

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

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

		<guid isPermaLink="false">http://digwp.com/?p=5440</guid>
		<description><![CDATA[For some projects, it&#8217;s nice to output clean, well-formatted markup. Using theme template files enables great control over most of your (X)HTML formatting, but not so much for automated functionality involving stuff like widgets and custom menus. One of my current projects requires clean, semantic HTML markup for all web pages, but also takes advantage [...]]]></description>
			<content:encoded><![CDATA[<p>For some projects, it&#8217;s nice to output clean, well-formatted markup. Using theme template files enables great control over most of your (X)HTML formatting, but not so much for automated functionality involving stuff like widgets and custom menus. One of my current projects requires clean, semantic HTML markup for all web pages, but also takes advantage of WordPress&#8217; custom-menu functionality to make things easy. In this <abbr title="Digging into WordPress">DiW</abbr> article, we&#8217;ll see how to enjoy both: WordPress custom menus <em>and</em> clean, well-formatted HTML markup.</p>
<p><span id="more-5440"></span></p>
<h3>Customizing HTML displayed with wp_nav_menu()</h3>
<p>By default, <a href="http://digwp.com/2010/08/using-menus-in-wordpress-3-0/" title="Using Menus in WordPress 3.0">WordPress custom menus</a> are displayed in your theme template using the <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu</a> function, which by default outputs markup that looks like this:</p>
<pre><code>&lt;div class="menu-test-container"&gt;&lt;ul id="menu-test" class="menu"&gt;&lt;li id="menu-item-6" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-6"&gt;&lt;a href="http://example.com/"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-7" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7"&gt;&lt;a href="http://example.com/demos/"&gt;Demos&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-8" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8"&gt;&lt;a href="http://example.com/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-9" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-9"&gt;&lt;a href="http://example.com/docs/"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</code></pre>
<p>That&#8217;s a <em>mess</em> of <code>class</code> and <code>id</code> attributes, plus an extra <code>&lt;div&gt;</code> container to boot. Fortunately, the <code>wp_nav_menu()</code> provides some useful parameters for customizing the display of your custom navigation menus. Here is a list of the <em>default parameters</em>:</p>
<pre><code>&lt;?php $defaults = array(
  'theme_location'  =&gt; ,
  'menu'            =&gt; , 
  'container'       =&gt; 'div', 
  'container_class' =&gt; 'menu-{menu slug}-container', 
  'container_id'    =&gt; ,
  'menu_class'      =&gt; 'menu', 
  'menu_id'         =&gt; ,
  'echo'            =&gt; true,
  'fallback_cb'     =&gt; 'wp_page_menu',
  'before'          =&gt; ,
  'after'           =&gt; ,
  'link_before'     =&gt; ,
  'link_after'      =&gt; ,
  'items_wrap'      =&gt; '&lt;ul id=\"%1$s\" class=\"%2$s\"&gt;%3$s&lt;/ul&gt;',
  'depth'           =&gt; 0,
  'walker'          =&gt; );
?&gt;</code></pre>
<p>Of these parameters, <code>$container</code> lets you specify how to wrap the <code>&lt;ul&gt;</code> element, using either <code>'div'</code>, <code>'nav'</code>, or <code>false</code>. So by specifying <code>false</code> for the <code>$container</code> parameter, we can simplify markup by removing the <code>&lt;div&gt;</code> container. The <code>wp_nav_menu</code> function also provides two more optional parameters for customizing menu markup:</p>
<ul>
<li><code>$items_wrap</code> &ndash; &#8220;Whatever to wrap the items with an ul, and how to wrap them with&#8221; (source: WP Codex)</li>
<li><code>$walker</code> &ndash; &#8220;Custom walker object to use (Note: You must pass an actual object to use, not a string)&#8221; (source: WP Codex)</li>
</ul>
<p>These <em>sound</em> useful, but I haven&#8217;t had much luck with either. The <code>$items_wrap</code> didn&#8217;t seem to do anything, but there are plenty of <a href="http://wordpress.stackexchange.com/questions/14037/menu-items-description/14039#14039">custom</a> <a href="http://erikshosting.com/wordpress-tips-code/building-a-wordpress-walker-creating-custom-dynamic-menu-outputs/">walker</a> <a href="http://benword.com/2011/how-to-hide-that-youre-using-wordpress/">scripts</a> available for further experimentation and customization. If you can get them to work properly, <strong>a custom walker provides complete control over custom-menu markup</strong> displayed with the <code>wp_nav_menu</code> tag. Unfortunately, I was unable to get very far with any of them, so I sought an alternate method..</p>
<h3>An alternative approach for custom markup</h3>
<p>After fiddling with a few of the various custom walkers, I decided to find an <em>easier way</em> to customize and format WordPress nav/menu markup. The walkers are fairly extensive and complex, and just seem like overkill for building a simple list of custom menu items. After some digging through the WordPress Codex, I found the <em>perfect</em> function for crafting squeaky-clean WordPress menus: <a href="http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items">wp_get_nav_menu_items</a>. As the name implies, <code>wp_get_nav_menu_items</code> returns the items from your custom navigation menus (as created in the WP Admin → Appearance → Menus panel). Thus, you can use this function to mark up your custom menus however you want. For my particular project, the desired format looks like this:</p>
<pre><code>&lt;nav&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href="http://example.com/"&gt;Home&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/demos/"&gt;Demos&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/docs/"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/nav&gt;</code></pre>
<p>Trying to do this with the commonly used <code>wp_nav_menu</code> function and a custom walker is possible, but it&#8217;s <em>much easier</em> building the menu structure from scratch, using only what&#8217;s required to make it happen. So alternately we use <code>wp_get_nav_menu_items</code> and begin with the <a href="http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items#Building_simple_menu_list">example function</a> provided at the Codex. After wrapping it in a <code>function</code> and customizing the output, we have the <code>clean_custom_menus()</code> function, ready for copy/paste into your theme&#8217;s <code>functions.php</code> file:</p>
<pre><code>// custom menu example @ http://digwp.com/2011/11/html-formatting-custom-menus/
function clean_custom_menus() {
	$menu_name = 'nav-primary'; // specify custom menu slug
	if (($locations = get_nav_menu_locations()) &amp;&amp; isset($locations[$menu_name])) {
		$menu = wp_get_nav_menu_object($locations[$menu_name]);
		$menu_items = wp_get_nav_menu_items($menu-&gt;term_id);

		$menu_list = '&lt;nav&gt;' ."\n";
		$menu_list .= "\t\t\t\t". '&lt;ul&gt;' ."\n";
		foreach ((array) $menu_items as $key =&gt; $menu_item) {
			$title = $menu_item-&gt;title;
			$url = $menu_item-&gt;url;
			$menu_list .= "\t\t\t\t\t". '&lt;li&gt;&lt;a href="'. $url .'"&gt;'. $title .'&lt;/a&gt;&lt;/li&gt;' ."\n";
		}
		$menu_list .= "\t\t\t\t". '&lt;/ul&gt;' ."\n";
		$menu_list .= "\t\t\t". '&lt;/nav&gt;' ."\n";
	} else {
		// $menu_list = '&lt;!-- no list defined --&gt;';
	}
	echo $menu_list;
}</code></pre>
<p>After placing in your <code>functions.php</code> file, you can call the function and display your custom menus anywhere in your theme by calling it directly:</p>
<p><code>&lt;?php if (function_exists(clean_custom_menus())) clean_custom_menus(); ?&gt;</code></p>
<p>Then, you can customize the <code>clean_custom_menus()</code> function as follows:</p>
<ol>
<li><strong>Line 3:</strong> specify your custom-menu slug</li>
<li><strong>Lines 8 thru 15:</strong> customize markup, tabs, and line breaks as needed</li>
<li><strong>Line 17:</strong> uncomment <code>else</code> condition and customize if needed</li>
</ol>
<p>For lines 8-15, anything is possible &ndash; you can include whatever list items, markup, and attributes required. Additionally, you can tab and indent markup to line up with page markup using <code>\n</code> for a new line and <code>\t</code> for a tab space. The fastest, easiest way to use this function is to copy/paste into your theme and then check out your list markup. For example, if the nav list is too far to the left, add some more tabs. You can also add <code>class</code> and <code>id</code> attributes, include custom items, and even manipulate which list items are displayed (<code>$url</code>, <code>$title</code>, etc.). After a little fine-tuning, <strong>the <code>wp_get_nav_menu_items()</code> function enables clean, well-formatted markup for your custom menus</strong>.</p>
<h3>Quick Summary</h3>
<p>In this article, we explain two ways to clean up and customize WordPress&#8217; custom-menu markup. Either of these methods will take your code from this:</p>
<pre><code>&lt;div class="menu-test-container"&gt;&lt;ul id="menu-test" class="menu"&gt;&lt;li id="menu-item-6" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-6"&gt;&lt;a href="http://example.com/"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-7" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7"&gt;&lt;a href="http://example.com/demos/"&gt;Demos&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-8" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8"&gt;&lt;a href="http://example.com/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-9" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-9"&gt;&lt;a href="http://example.com/docs/"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</code></pre>
<p>..to this:</p>
<pre><code>&lt;nav&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href="http://example.com/"&gt;Home&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/demos/"&gt;Demos&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/docs/"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/nav&gt;</code></pre>
<p>..or whatever HTML structure that&#8217;s required. You can achieve this with either of these methods:</p>
<ul>
<li>Combine <code>wp_nav_menu()</code> with a custom walker class</li>
<li>Combine <code>wp_get_nav_menu_items()</code> with the <code>clean_custom_menus()</code> function</li>
</ul>
<p>As usual, if you know of better ways of doing something, please share in the comments! Thanks for reading Digging into WordPress :)</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/11/html-formatting-custom-menus/">Permalink</a> | <a href="http://digwp.com/2011/11/html-formatting-custom-menus/#comments">43 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/11/html-formatting-custom-menus/&title=HTML Formatting for Custom Menus">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/html/" rel="tag">HTML</a>, <a href="http://digwp.com/tag/menu/" rel="tag">menu</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/11/html-formatting-custom-menus/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Create an Articles-Only Feed</title>
		<link>http://digwp.com/2011/08/custom-feeds/</link>
		<comments>http://digwp.com/2011/08/custom-feeds/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 15:33:10 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[query_posts]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=5179</guid>
		<description><![CDATA[WordPress makes it easy to publish content in any number of categories, with any number of tags, and with any type of custom post format. So for example, in addition to full articles, you could also offer screencasts, links, side posts, tweets, and all sorts of other peripheral content. Complementary material may work great for [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress makes it easy to publish content in any number of categories, with any number of tags, and with any type of custom post format. So for example, in addition to full articles, you could also offer screencasts, links, side posts, tweets, and all sorts of other peripheral content. Complementary material may work great for visitors surfing around your site, but including all of that extra stuff in your RSS feed dilutes the potency of your main articles. The idea here is that your visitors will subscribe to the more <em>focused</em> content.</p>
<p><span id="more-5179"></span></p>
<p>In this post, we create a custom, &#8220;articles-only&#8221; feed for visitors who want to subscribe to the main content only, without all the side stuff. The technique is actually pretty flexible, and works great to create just about <em>any</em> type of custom WordPress feed content. It&#8217;s pretty easy to do, requiring a whopping two steps to make it happen..</p>
<h3>Step 1: Create the custom page template</h3>
<p>Go to your theme directory and create a new <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> file named <code>article-feed.php</code>. Then add the following code (don&#8217;t worry it&#8217;s actually not that bad):</p>
<pre><code>&lt;?php 
/* 
Template Name: Article Feed
*/
$numposts = 10; // number of posts in feed
$posts = query_posts('showposts='.$numposts.'&amp;cat=3');
$more = 1;

header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '&lt;?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'&gt;';
?&gt;

&lt;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/"
	&lt;?php do_action('rss2_ns'); ?&gt;
&gt;
&lt;channel&gt;
	&lt;title&gt;&lt;?php bloginfo_rss('name'); wp_title_rss(); ?&gt; - Article Feed&lt;/title&gt;
	&lt;atom:link href="&lt;?php self_link(); ?&gt;" rel="self" type="application/rss+xml" /&gt;
	&lt;link&gt;&lt;?php bloginfo_rss('url') ?&gt;&lt;/link&gt;
	&lt;description&gt;&lt;?php bloginfo_rss("description") ?&gt;&lt;/description&gt;
	&lt;lastBuildDate&gt;&lt;?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?&gt;&lt;/lastBuildDate&gt;
	&lt;?php the_generator( 'rss2' ); ?&gt;
	&lt;language&gt;&lt;?php echo get_option('rss_language'); ?&gt;&lt;/language&gt;
	&lt;sy:updatePeriod&gt;&lt;?php echo apply_filters( 'rss_update_period', 'hourly' ); ?&gt;&lt;/sy:updatePeriod&gt;
	&lt;sy:updateFrequency&gt;&lt;?php echo apply_filters( 'rss_update_frequency', '1' ); ?&gt;&lt;/sy:updateFrequency&gt;
	&lt;?php do_action('rss2_head'); ?&gt;
	&lt;?php while( have_posts()) : the_post(); ?&gt;

	&lt;item&gt;
		&lt;title&gt;&lt;?php the_title_rss(); ?&gt;&lt;/title&gt;
		&lt;link&gt;&lt;?php the_permalink_rss(); ?&gt;&lt;/link&gt;
		&lt;comments&gt;&lt;?php comments_link(); ?&gt;&lt;/comments&gt;
		&lt;pubDate&gt;&lt;?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?&gt;&lt;/pubDate&gt;
		&lt;dc:creator&gt;&lt;?php the_author(); ?&gt;&lt;/dc:creator&gt;
&lt;?php the_category_rss(); ?&gt;
		&lt;guid isPermaLink="false"&gt;&lt;?php the_guid(); ?&gt;&lt;/guid&gt;
&lt;?php if (get_option('rss_use_excerpt')) : ?&gt;

		&lt;description&gt;&lt;![CDATA[&lt;?php the_excerpt_rss() ?&gt;]]&gt;&lt;/description&gt;
&lt;?php else : ?&gt;

		&lt;description&gt;&lt;![CDATA[&lt;?php the_excerpt_rss() ?&gt;]]&gt;&lt;/description&gt;
	&lt;?php if ( strlen( $post-&gt;post_content ) &gt; 0 ) : ?&gt;

		&lt;content:encoded&gt;&lt;![CDATA[&lt;?php the_content() ?&gt;]]&gt;&lt;/content:encoded&gt;
	&lt;?php else : ?&gt;

		&lt;content:encoded&gt;&lt;![CDATA[&lt;?php the_excerpt_rss() ?&gt;]]&gt;&lt;/content:encoded&gt;
	&lt;?php endif; ?&gt;
&lt;?php endif; ?&gt;

		&lt;wfw:commentRss&gt;&lt;?php echo get_post_comments_feed_link(); ?&gt;&lt;/wfw:commentRss&gt;
		&lt;slash:comments&gt;&lt;?php echo get_comments_number(); ?&gt;&lt;/slash:comments&gt;
&lt;?php rss_enclosure(); ?&gt;
&lt;?php do_action('rss2_item'); ?&gt;

	&lt;/item&gt;
	&lt;?php endwhile; ?&gt;

&lt;/channel&gt;
&lt;/rss&gt;</code></pre>
<p>This is basically just a typical WordPress feed template, but with some extra query action to make it do what we want. In the first few lines of code, we specify how many posts to display, which categories to include, and whether to display full posts or excerpts:</p>
<pre><code>$numposts = 10; // number of posts in feed
$posts = query_posts('showposts='.$numposts.'&amp;cat=3');
$more = 1;</code></pre>
<p>Using this default code, the custom feed will show 10 posts from category 3. And with <code>$more</code> set to <code>1</code>, the <em>full</em> article will be included in the feed. This is where you customize your new feed to include whatever you want. So for example, if we post articles in three different categories, say with IDs of <code>1</code>, <code>2</code>, and <code>3</code>, we would modify our code to look like this:</p>
<pre><code>$numposts = 10; // number of posts in feed
$posts = query_posts('showposts='.$numposts.'&amp;cat=1,2,3');
$more = 1;</code></pre>
<p>The <code>query_posts</code> function is quite flexible and provides all of the parameters needed to set up just about any customized feed content. You can exclude/include categories, display specific types of posts, change the number of posts displayed, and so much more. For a full list of options, check out <a href="http://codex.wordpress.org/Function_Reference/query_posts">query_posts at the WordPress Codex</a>.</p>
<h3>Step 2: Create the custom Page in the WP Admin</h3>
<p>Once you have the custom Page Template uploaded to your server, log into the WordPress Admin and visit the &#8220;Add New Page&#8221; screen (<strong>Pages &gt; Add New</strong>). Create a new page named &#8220;Articles-Only Feed&#8221; (or whatever), and select the newly added &#8220;articles&#8221; page template from the drop-down menu:</p>
<p><img src="http://digwp.com/wp-content/blog-images/articles-only-template.gif" alt="" /></p>
<p>While you&#8217;re there in the Admin creating this new custom-feed page, take a moment to be mindful of the feed <abbr title="Uniform Resource Locator">URL</abbr> and title, which may be set to whatever works best:</p>
<p><img src="http://digwp.com/wp-content/blog-images/articles-only-page.gif" alt="" /></p>
<p>Once everything is ready, finish it up by publishing the page to your site. Then check that your new feed is working by visiting the URL of the new page you just created in the WP Admin. Here at <a href="http://digwp.com/">DigWP.com</a>, our articles-only feed is available at <a href="http://digwp.com/articles/" title="DigWP.com - Articles Feed"><code>http://digwp.com/articles/</code></a>.</p>
<h3>Wrap-up + additional resources</h3>
<p>In addition to the easy-breezy two-step custom-feed tutorial in this post, here are some additional resources that are sort of related to this general topic:</p>
<ul>
<li><a href="http://digwp.com/2011/04/tumblr-links-post-formats/">Tumblr Links with Post Formats</a></li>
<li><a href="http://digwp.com/2009/09/easy-custom-feeds-in-wordpress/">Easy Custom Feeds in WordPress</a></li>
<li><a href="http://digwp.com/2009/09/tumblr-style-links-for-posts-and-feeds/">How to Implement Tumblr-Style Links for Posts and Feeds</a></li>
</ul>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/08/custom-feeds/">Permalink</a> | <a href="http://digwp.com/2011/08/custom-feeds/#comments">12 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/08/custom-feeds/&title=Create an Articles-Only Feed">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/feeds/" rel="tag">feeds</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/query_posts/" rel="tag">query_posts</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/08/custom-feeds/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Tumblr Links with Post Formats</title>
		<link>http://digwp.com/2011/04/tumblr-links-post-formats/</link>
		<comments>http://digwp.com/2011/04/tumblr-links-post-formats/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 17:49:20 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[post-formats]]></category>
		<category><![CDATA[Theme]]></category>

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

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

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

		<guid isPermaLink="false">http://digwp.com/?p=2308</guid>
		<description><![CDATA[One of the nice things about using WordPress&#8217; new post-thumbnails feature is that they provide tons of flexibility in terms of where and how you display your post thumbnails. By design, post thumbnails are not included within post content, so they will not be displayed in your blog posts unless you call them specifically with [...]]]></description>
			<content:encoded><![CDATA[<p>One of the nice things about using WordPress&rsquo; new post-thumbnails feature is that they provide tons of flexibility in terms of <em>where</em> and <em>how</em> you display your post thumbnails. By design, post thumbnails are not included within post content, so they will not be displayed in your blog posts unless you call them specifically with the proper template tag:</p>
<pre><code>&lt;?php the_post_thumbnail(); ?&gt;</code></pre>
<p>When included within the loop, <code>the_post_thumbnail()</code> will output the markup for the post&rsquo;s thumbnail, linked to a full-size or pre-sized version of the image. Of course, there are a <a href="http://wpengineer.com/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/" title="The Ultimative Guide For the_post_thumbnail In WordPress 2.9">few more awesome things</a> that you can do with <a href="http://codex.wordpress.org/Template_Tags/the_post_thumbnail" title="WordPress Codex: Template Tags/the_post_thumbnail">the_post_thumbnail</a>. Now that we&rsquo;ve seen how to include thumbnails in <em>post</em> content, let&rsquo;s do it for <em>feed</em> content..</p>
<p><span id="more-2308"></span></p>
<h3>Display Post Thumbnails in Feed Content</h3>
<p>To include post-thumbnails in your feeds, we need to filter WordPress&rsquo; feed functionality and inject the required template tag into both <em>feed-excerpt</em> and <em>full-feed</em> content:</p>
<pre><code>// show post thumbnails in feeds
function diw_post_thumbnail_feeds($content) {
	global $post;
	if(has_post_thumbnail($post-&gt;ID)) {
		$content = '&lt;div&gt;' . get_the_post_thumbnail($post-&gt;ID) . '&lt;/div&gt;' . $content;
	}
	return $content;
}
add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
add_filter('the_content_feed', 'diw_post_thumbnail_feeds');</code></pre>
<p>Include that code in your active theme&rsquo;s <code>functions.php</code> file and your feeds will display the post thumbnail <em>before</em> each post. To display the post thumbnail <em>after</em> the post content, a slight adjustment is made to the fourth line of the function:</p>
<p><code>$content = $content . '&lt;div&gt;' . get_the_post_thumbnail($post-&gt;ID) . '&lt;/div&gt;';</code></p>
<p>The <code>&lt;div&gt;</code> will prevent the post text from wrapping around the post thumbnail, but theoretically its removal would enable the post content to wrap around the image:</p>
<p><code>$content = get_the_post_thumbnail($post-&gt;ID) . $content;</code></p>
<p>As easy and flexible as it is working with <code>the_post_thumbnail()</code>, there may be situations where you need more control over the appearance and functionality of your posts&rsquo; attached images. Fortunately, <a href="http://perishablepress.com/press/2008/12/22/wordpress-custom-fields-tips-tricks/" title="WordPress Custom Fields, Part II: Tips and Tricks">WordPress&rsquo; custom fields</a> and <a href="http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/" title="Awesome Image-Attachment Recipes for WordPress">image-attachment functionality</a> enable just about any custom configuration you can imagine.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/06/show-post-thumbnails-in-feeds/">Permalink</a> | <a href="http://digwp.com/2010/06/show-post-thumbnails-in-feeds/#comments">16 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/06/show-post-thumbnails-in-feeds/&title=Show Post Thumbnails in Feeds">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/feeds/" rel="tag">feeds</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/thumbnails/" rel="tag">thumbnails</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/06/show-post-thumbnails-in-feeds/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Specify Unique CSS File Per Post</title>
		<link>http://digwp.com/2010/05/specify-unique-css-file-per-post/</link>
		<comments>http://digwp.com/2010/05/specify-unique-css-file-per-post/#comments</comments>
		<pubDate>Mon, 10 May 2010 21:20:39 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2082</guid>
		<description><![CDATA[I&#8217;m a HUGE fan of being able to link up a CSS file on a per-page basis. I just find it extremely common that a page needs CSS styling unique to it, and I hate litering a sites main stylesheet with customizations that only one particular page needs. We&#8217;ve talked about this before, and even [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a HUGE fan of being able to link up a CSS file on a per-page basis. I just find it extremely common that a page needs CSS styling unique to it, and I hate litering a sites main stylesheet with customizations that only one particular page needs. We&#8217;ve talked about this before, and even created a <a href="http://digwp.com/2010/02/custom-css-per-post/">custom method for doing so</a>, as well as mentioned the <a href="http://wordpress.org/extend/plugins/art-direction/">art direction plugin</a>, which makes this easily possible. </p>
<p>Both of those methods are still sweet, but I find in general that I like to write my CSS in actual CSS files I keep in my theme and can edit using whatever CSS editor I like, as well as keep things clean and simple in the admin. So, I&#8217;ve altered the technique a bit.</p>
<p><span id="more-2082"></span></p>
<p>The idea is to add a simple text input to the page editor, right underneath the content area, where you can manually specify the name of a CSS file. In the image below, you can see I&#8217;ve also added one for JavaScript.</p>
<p><img src="http://digwp.com/wp-content/blog-images/customfiles.png" width="590" height="177" alt="" title="" /></p>
<p>To add this to your site, it&#8217;s just some code to add to the functions.php file. Should work for any site.</p>
<pre><code>// Custom Stylesheet box in Pages/Posts
add_action('admin_menu', 'digwp_custom_css_hooks');
add_action('save_post', 'digwp_save_custom_css');
add_action('wp_head','digwp_insert_custom_css');
function digwp_custom_css_hooks() {
	add_meta_box('custom_css', 'Name of custom CSS file', 'digwp_custom_css_input', 'post', 'normal', 'high');
	add_meta_box('custom_css', 'Name of custom CSS file', 'digwp_custom_css_input', 'page', 'normal', 'high');
}
function digwp_custom_css_input() {
	global $post;
	echo '&lt;input type="hidden" name="custom_css_noncename" id="custom_css_noncename" value="'.wp_create_nonce('custom-css').'" /&gt;';
	echo '&lt;input type="text" name="custom_css" id="custom_css" style="width:100%;" value="'.get_post_meta($post-&gt;ID,'_custom_css',true).'" /&gt;';
}
function digwp_save_custom_css($post_id) {
	if (!wp_verify_nonce($_POST['custom_css_noncename'], 'custom-css')) return $post_id;
	if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) return $post_id;
	$custom_css = $_POST['custom_css'];
	update_post_meta($post_id, '_custom_css', $custom_css);
}
function digwp_insert_custom_css() {
	if (is_page() || is_single()) {
		if (have_posts()) : while (have_posts()) : the_post();
		  $filename = get_post_meta(get_the_ID(), '_custom_css', true);
		  if ($filename) {
			echo "&lt;link rel='stylesheet' type='text/css' href='" . get_bloginfo('template_url') . "/css/" . $filename . "' /&gt;";
          }
		endwhile; endif;
		rewind_posts();
	}
}</code></pre>
<p>If you are happy with just CSS only, you can stop there. If you would like the JavaScript box as well, here is that code.</p>
<pre><code>// Custom JavaScript in Pages/Posts  (...lots of repeated code, could be better)
add_action('admin_menu', 'digwp_custom_js_hooks');
add_action('save_post', 'digwp_save_custom_js');
add_action('wp_head','digwp_insert_custom_js');
function digwp_custom_js_hooks() {
	add_meta_box('custom_js', 'Name of custom JavaScript file', 'digwp_custom_js_input', 'post', 'normal', 'high');
	add_meta_box('custom_js', 'Name of custom JavaScript file', 'digwp_custom_js_input', 'page', 'normal', 'high');
}
function digwp_custom_js_input() {
	global $post;
	echo '&lt;input type="hidden" name="custom_js_noncename" id="custom_js_noncename" value="'.wp_create_nonce('custom-js').'" /&gt;';
	echo '&lt;input type="text" name="custom_js" id="custom_js" style="width:100%;" value="'.get_post_meta($post-&gt;ID,'_custom_js',true).'" /&gt;';
}
function digwp_save_custom_js($post_id) {
	if (!wp_verify_nonce($_POST['custom_js_noncename'], 'custom-js')) return $post_id;
	if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) return $post_id;
	$custom_js = $_POST['custom_js'];
	update_post_meta($post_id, '_custom_js', $custom_js);
}
function digwp_insert_custom_js() {
	if (is_page() || is_single()) {
		if (have_posts()) : while (have_posts()) : the_post();
		    $filename = get_post_meta(get_the_ID(), '_custom_js', true);
		    if ($filename) {
			 echo "&lt;script type='text/javascript' src='" . get_bloginfo('template_url') . "/js/" . $filename . "' &gt;&lt;/script&gt;";
            }
		endwhile; endif;
		rewind_posts();
	}
}</code></pre>
<p>You could probably combine these together a bit better than I have done here, it&#8217;s a bit redundant. </p>
<h3>How it Works</h3>
<p>There are three things going on here, which tap into three existing WordPress &#8220;hooks&#8221;.</p>
<ol>
<li>Adds text inputs to the page editing screen of the admin using the <code>admin_menu</code> hook and the <code>add_meta_box</code> function</li>
<li>Save the values of those text inputs when the page is saved using the <code>save_post</code> hook</li>
<li>Output <code>&lt;link&gt;</code> or <code>&lt;script&gt;</code> tags in the <code>&lt;head&gt;</code> of the site (when those values are present) using the <code>wp_head</code> hook.</li>
</ol>
<h3>The Result</h3>
<p>If you put the value &#8220;yeahbaby.css&#8221; in that input box, when that particular page loads, you are going to get this output in the <code>&lt;head&gt;</code>:</p>
<pre><code>&lt;link rel='stylesheet' type='text/css' href='http://yoursite.com/notes/wp-content/themes/your-theme/css/yeahbaby.css' /&gt;</code></pre>
<p>&#8220;yoursite.com&#8221; will obviously be your sites domain, and your-theme will the folder in which your currently active theme resides. Do keep that in mind, as should you change themes, you&#8217;ll need to move the &#8220;css&#8221; folder in that theme that contains these custom CSS files to the new theme. </p>
<h3>UPDATE (May 13, 2010)</h3>
<p>Notice how all the function names are prefixed by &#8220;digwp_&#8221; &#8211; that is in accordance to best practices described by Andrew Nacin <a href="http://www.andrewnacin.com/2010/05/11/in-wordpress-prefix-everything/">here</a>.</p>
<p>This has also been <a href="http://wordpress.org/extend/plugins/include-custom-files/">made into a plugin</a> by <a href="http://utkar.sh/">Utkarsh Kukreti</a>. Requires PHP5.</p>
<h3>Ways This Code Could Be Improved</h3>
<p>I was holding back on publishing this because there are a lot of ways it could be better. But I had mentioned it at the <a href="http://www.cmsexpo.net/">CMS Expo</a> and there was some interested and I said I would, so I&#8217;m releasing it a bit early. Here are things that could be better&#8230;</p>
<ul>
<li>Combine the functions together to create less redundancies between the CSS and JavaScript versions.</li>
<li>Allow for a comma-separated list in case multiple custom CSS files are needed.</li>
<li>Make it a plugin instead of custom functions. Add options screen to specify file path to custom CSS folder.</li>
</ul>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/05/specify-unique-css-file-per-post/">Permalink</a> | <a href="http://digwp.com/2010/05/specify-unique-css-file-per-post/#comments">21 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/05/specify-unique-css-file-per-post/&title=Specify Unique CSS File Per Post">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/05/specify-unique-css-file-per-post/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Custom Page Titles from Scratch</title>
		<link>http://digwp.com/2010/04/custom-page-titles/</link>
		<comments>http://digwp.com/2010/04/custom-page-titles/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 18:33:20 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[title]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1953</guid>
		<description><![CDATA[The titles of pages are controlled by the &#60;title> tag in the &#60;head> section of a website. They are important for all kinds of reasons. Telling the user where they are. The name of the page when bookmarked both locally and socially. They are important for SEO. So how do we typically handle page titles [...]]]></description>
			<content:encoded><![CDATA[<p>The titles of pages are controlled by the &lt;title> tag in the &lt;head> section of a website. They are important for all kinds of reasons. Telling the user where they are. The name of the page when bookmarked both locally and socially. They are important for SEO.  </p>
<p>So how do we typically handle page titles in WordPress? Hopefully we are A) Using a theme that uses <a href="http://digwp.com/2009/06/custom-wordpress-title-tags/">a pretty smart default page titling system</a> or B) using a plugin that helps us with this same task automatically, as most SEO plugins at least attempt.</p>
<p>The problem with A is that it doesn&#8217;t afford any way to individually override any particular page with a special title. With B, it depends on which plugin you use, but not all of them allow for <em>full</em> control over the <em>entire</em> title, often just the slug that fits into the overall chosen method.</p>
<p><img src="http://digwp.com/wp-content/blog-images/bendtomywill.jpg" width="549" height="268" alt="" title="" /></p>
<p>Finally fed up with both of these techniques, I rolled my own!</p>
<p><span id="more-1953"></span></p>
<h3>Step 1: Remove &lt;title></h3>
<p>Whatever you have for the &lt;title> tag in the header.php file, just get rid of it.</p>
<p><img src="http://digwp.com/wp-content/blog-images/removetitle.png" width="590" height="248" alt="" title="" /></p>
<p>We&#8217;ll be inserting that automatically in the wp_head(); function, so that needs to be there.</p>
<h3>Step 2: New stuff for functions.php file</h3>
<p>We&#8217;re doing three things here.</p>
<ol>
<li>Add a new input box to the admin pages for creating and editing new Posts/Pages</li>
<li>Save the the value of that input box when that Post/Page is saved</li>
<li>Echo out a new title as part of the wp_head() function</li>
</ol>
<pre><code>// Custom Page Titles
add_action('admin_menu', 'custom_title');
add_action('save_post', 'save_custom_title');
add_action('wp_head','insert_custom_title');
function custom_title() {
	add_meta_box('custom_title', 'Change page title', 'custom_title_input_function', 'post', 'normal', 'high');
	add_meta_box('custom_title', 'Change page title', 'custom_title_input_function', 'page', 'normal', 'high');
}
function custom_title_input_function() {
	global $post;
	echo '&lt;input type="hidden" name="custom_title_input_hidden" id="custom_title_input_hidden" value="'.wp_create_nonce('custom-title-nonce').'" /&gt;';
	echo '&lt;input type="text" name="custom_title_input" id="custom_title_input" style="width:100%;" value="'.get_post_meta($post-&gt;ID,'_custom_title',true).'" /&gt;';
}
function save_custom_title($post_id) {
	if (!wp_verify_nonce($_POST['custom_title_input_hidden'], 'custom-title-nonce')) return $post_id;
	if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) return $post_id;
	$customTitle = $_POST['custom_title_input'];
	update_post_meta($post_id, '_custom_title', $customTitle);
}
function insert_custom_title() {
	if (have_posts()) : the_post();
	  $customTitle = get_post_meta(get_the_ID(), '_custom_title', true);
	  if ($customTitle) {
		echo "&lt;title&gt;$customTitle&lt;/title&gt;";
      } else {
    	echo "&lt;title&gt;";
	      if (is_tag()) {
	         single_tag_title("Tag Archive for &amp;quot;"); echo '&amp;quot; - '; }
	      elseif (is_archive()) {
	         wp_title(''); echo ' Archive - '; }
	      elseif ((is_single()) || (is_page()) &amp;&amp; (!(is_front_page())) ) {
	         wp_title(''); echo ' - '; }
	      if (is_home()) {
	         bloginfo('name'); echo ' - '; bloginfo('description'); }
	      else {
	          bloginfo('name'); }
	      if ($paged&gt;1) {
	         echo ' - page '. $paged; }
        echo "&lt;/title&gt;";
    }
    else :
      echo "&lt;title&gt;Page Not Found | Envision&lt;/title&gt;";
	endif;
	rewind_posts();
}</code></pre>
<p>The new input box we are putting on the page saves its value as a custom field on the Post/Page you are on. The key of that custom field is &#8220;_custom_title&#8221;, so it doesn&#8217;t show in the regular custom field list (custom fields that start with underscores don&#8217;t).</p>
<p>Now when any front-end page of the site loads, it checks that page to see if that custom field exists. If it does exist, it uses that value exactly for the page title. If it doesn&#8217;t, it defaults to a generically smart page title structure.</p>
<h3>Result</h3>
<p>This is the box that now is available when creating or editing a Page/Post:</p>
<p><img src="http://digwp.com/wp-content/blog-images/custompagetitle.png" width="590" height="194" alt="" title="" /></p>
<p>And that is what will be used:</p>
<p><img src="http://digwp.com/wp-content/blog-images/customtitleexerted.jpg" width="520" height="200" alt="" title="" /></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/04/custom-page-titles/">Permalink</a> | <a href="http://digwp.com/2010/04/custom-page-titles/#comments">21 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/04/custom-page-titles/&title=Custom Page Titles from Scratch">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/title/" rel="tag">title</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/04/custom-page-titles/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Call a Widget with a Shortcode</title>
		<link>http://digwp.com/2010/04/call-widget-with-shortcode/</link>
		<comments>http://digwp.com/2010/04/call-widget-with-shortcode/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 17:30:03 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[widgets]]></category>

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

