<?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>Mike Van WinkleMeta Tag Titles and Descriptions for Your WordPress site. | Mike Van Winkle</title>
	<atom:link href="http://www.mikevanwinkle.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikevanwinkle.com</link>
	<description>Wordpress/PHP Developer</description>
	<lastBuildDate>Tue, 31 Jan 2012 00:02:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Meta Tag Titles and Descriptions for Your WordPress site.</title>
		<link>http://www.mikevanwinkle.com/wordpress/meta-tag-titles-and-descriptions-for-your-wordpress-site/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/meta-tag-titles-and-descriptions-for-your-wordpress-site/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 13:46:27 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[meta tags]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress How To]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=364</guid>
		<description><![CDATA[There are many good plugins out there the help you easily add meta tags to your site. All-in-one-SEO is probably the most popular of all the options. But there several reason why you may want to manually add this code to your template. For one, you may be a template designer and want your templates to come [...]]]></description>
			<content:encoded><![CDATA[<p>There are many good plugins out there the help you easily add meta tags to your site. All-in-one-SEO is probably the most popular of all the options. But there several reason why you may want to manually add this code to your template.</p>
<p>For one, you may be a template designer and want your templates to come pre-installed with this SEO friend feature.</p>
<p>Second, you may be having issues with Facebook link sharing not working. WordPress plugins use the wp_head() hook to access your template. But you have no control over the order. If you are using more than a dozen plugins your meta tags can get buried under tons of other code. This can prevent some bots from finding them. Indeed on several of my site Facebook&#8217;s bot was not finding them.</p>
<p>Third, it is just always good to do things without plugins if possible. Call it Occum&#8217;s Razor of web site building, the less code you use, the better.</p>
<p>Luck for us, it is extremely simple to add code for meta tags and descriptions without knowing much about wordpress or PHP.</p>
<p>Open the header.php file in your theme and paste in the following code:</p>
<pre>
<div id="_mcePaste">&lt;?php if(is_singular()) { ?&gt;</div>
<div id="_mcePaste">&lt;?php</div>
<div id="_mcePaste">global $post;</div>
<div id="_mcePaste">?&gt;</div>
<div id="_mcePaste">&lt;?php $recent = new WP_query('p='.$post-&gt;ID);</div>
<div id="_mcePaste">while($recent-&gt;have_posts()) : $recent-&gt;the_post(); ?&gt;</div>
<div id="_mcePaste">&lt;meta name="title" content="&lt;?php the_title(); ?&gt;"&gt;</div>
<div id="_mcePaste">&lt;meta name="description" content="&lt;?php the_content_rss('', TRUE, '', 50); ?&gt;"&gt;</div>
<div id="_mcePaste">&lt;?php endwhile; ?&gt;</div>
<div id="_mcePaste">&lt;?php } else { ?&gt;</div>
<div id="_mcePaste">&lt;meta name="title" content="&lt;?php bloginfo('title'); ?&gt;"&gt;</div>
<div id="_mcePaste">&lt;meta name="description" content="&lt;?php bloginfo('description'); ?&gt;"&gt;</div>
<div id="_mcePaste">&lt;?php } ?&gt;</div>
</pre>
<p>So what&#8217;s going on here? First, we&#8217;re checking to see if the post is a single post using the WordPress Conditional tag &lt;?php if(is_singular()); ?&gt;<em> </em>because we&#8217;ll to pull the title and the description of the individual post for our meta tags. But to do this, we need to get some information about the post, which is why we use the call <code><em>global $post</em></code>. This will give us information about the current post. Particularly it allows us access to <code>$post-&gt;ID</code> to query information about the post using <code>WP_query</code>.</p>
<p>The query we us looks like this:</p>
<pre><code>$recent = new WP_query('p='.$post-&gt;ID); </code></pre>
<p>Once we have the query we put it into the standard wordpress loop:</p>
<pre><code>while($recent-&gt;have_posts()) : $recent-&gt;the_post();</code></pre>
<p>Then we use the standard WordPress tag &lt;?php the_title(); ?&gt; to pull in the META TITLE and &lt;? the_content_rss() ?&gt; to get the description. Notice, we are not using &lt;?php the_excerpt(); ?&gt;. This is because this WordPress tag prints the excerpt with a &#8220;read more&#8221; link in it. This will seriously screw up your theme. Using <a title="The Content RSS" href="http://codex.wordpress.org/Function_Reference/the_content_rss">&lt;?php the_content_rss(); ?&gt;</a> allows us to specify how many words of the content to pull in. But the second parameter has to be set to TRUE to avoid pulling in a &#8220;read more&#8221; link.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/meta-tag-titles-and-descriptions-for-your-wordpress-site/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Object Caching 317/364 objects using apc

Served from: www.mikevanwinkle.com @ 2012-02-04 19:09:54 -->
