Skip to content

Awesome WordPress SEO With Custom Fields

SEO is something I’ve discussed before here on [wp], but here we’re going to dive into a slightly more specific area: post titles, urls and title tags.

Your average WordPress [theme] will take the title you put into the post and output it as the <title>, the post title in archive pages and send it as the title to RSS readers. That’s not really the most exciting way of doing things or the way that offers the most customisation; I want to be able to use a title written for search engines and use that as the <title>, another written for archives perhaps with some emphasis and one final one for RSS readers. With custom fields, it’s easy.

What? If?

First we need a basic understanding. Using something similar to the following we can see if a custom field exists and if it does display it. If it doesn’t, we’ll do something else:

<?php
$name = get_post_custom_values("Custom-Field-Name");
if ( is_array($name) ) { ?>
<?php echo get_post_meta($post->ID, "Custom-Field-Name", true); ?>
<?php }	else { ?>
Do some stuff
<?php }	?>Code language: PHP (php)

That’s the fundamental bit of info we need.

Show a specific title to the archives

This one’s fairly simple. We’re going to create a custom field ‘archive-title’ and in that you can type any title you want and if you pop the code in the correct places you’ll be able to use any type of HTML you like – for example your could have:

A title with a bit of <em>emphasis</em>
Code language: HTML, XML (xml)

or even…

A title with some <b>bold!</b>
Code language: HTML, XML (xml)

The code to display the custom field (and falls back to the_title) is as follows:

<?php
$archivetitle = get_post_custom_values("archive-title");
if ( is_array($archivetitle) ) { ?>
<?php echo get_post_meta($post->ID, "archive-title", true); ?>
<?php }	else { ?>
<?php the_title(); ?>
<?php } ?>Code language: HTML, XML (xml)

A specific title for the <title> tag

It’s pretty much the same for the <title> except you’ll need a different custom field name and obviously the code goes in the header:

<?php
$titletag = get_post_custom_values("tag-title");
if ( is_array($archivetitle) ) { ?>
<?php echo get_post_meta($post->ID, "tag-title", true); ?>
<?php }	else { ?>
<?php the_title(); ?>
<?php } ?>Code language: HTML, XML (xml)

A specific title for RSS readers

And finally, for RSS readers you can just change the title in the post editor. It’s that simple. With these three bits of info up your sleeve, you can boost for SEO. In theory anyway. At the very least, you can start writing for readers, not search engines.

Yay! 🎉 You made it to the end of the article!
Alex Denning
Share:

5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Jenny
June 4, 2010 2:44 pm

great post 😀 I’m gonna try this right now 😀

Dhany
March 15, 2010 12:58 pm

Thanks for this great SEO WP post. I’ve just bookmarked it in Delicious. I am sure I will reference it again. 🙂

Best Practices for Creating Unique Blog Posts | WPShout.com
January 27, 2010 5:36 pm

[…] replacement, emphasis, bold, the lot are all possible thanks to custom fields. Expanding further on this post, unique titles with image replacement are really easy to do. You just need to create a custom field […]

Il meglio della settimana #39 | BigThink
November 21, 2009 10:34 am

[…] Awesome WordPress SEO with custom fields Ottimizzare il proprio blog lato SEO, grazie ai campi personalizzati. […]

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!