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:

$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:

$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:

$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.

Alex Denning

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

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

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 |
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)!

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

25 Best Free WordPress Themes (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...