CodingWordPress

How to Automatically Add Meta Title Tags to Your Posts and Pages in WordPress

Meta Title Tag

As you may know, having a unique and descriptive meta title tag is a good way to optimize a webpage for search engine rankings. The beauty of WordPress is that you can automate a lot of processes that would otherwise take you forever to do manually. For instance, creating meta title tags that are unique to each page.

This article will show you how to automatically generate unique meta title tags for each of your posts and pages on WordPress — saving you a lot of time and effort.

The Plugin Method

There are several free plugins you can download to automatically generate your meta title tags, but there’s only one that I use and that’s SEO Title Tag. I’ve tried a few different ones, but this one did exactly what I wanted and it’s very simple to implement. Here are the steps:

1. Download the plugin. Long story short, download SEO Title Tag V2.3.3. Do not download any later versions of the plugin, as they do not work properly. I’ve tried getting support for the later versions, but there is none. Many users have complained about it, but it still hasn’t been fixed. And remember, do not upgrade to a higher version once you have activated it, as it will stop working.
2. Activate the plugin.
3. Replace a piece of code. Under Presentation -> Theme Editor in the WordPress admin, select “Header” from the list and replace:

<title><?php bloginfo(‘name’); wp_title(); ?></title>

with:

<title><?php if (function_exists(‘seo_title_tag’)) { seo_title_tag(); } else { bloginfo(‘name’); wp_title();} ?></title>

4. Now go into the SEO Title Tag section in your WordPress admin and format the title as you want. I prefer to format the title like this: Post Title – Site Title

This format puts emphasis on the title of the post in the front. And then, ends with the site title which gets repeated on every page. This combination of keywords will increase the probability of hitting all of your major keywords. Format it any way you want.

Without a Plugin Method

Adding meta title tags can also be done without a plugin, using PHP coding.

Under Presentation -> Theme Editor in the WordPress admin, select “Header” from the list and replace:

<title><?php bloginfo(‘name’); wp_title(); ?></title>

with something like this:

<?php
$blog_title = get_bloginfo(‘name’);
if (is_home()) {
$blog_title = get_bloginfo(‘name’) . ” – ” . get_bloginfo(‘description’);
}
if (is_single()) {
$blog_title = get_the_title() . ” – ” . get_bloginfo(‘name’);
}
if (is_category()) {
$blog_title = single_cat_title(“”,false) . ” archive – ” . get_bloginfo(‘name’);
}
if (is_page()) {
$blog_title = the_title() . ” – ” . get_bloginfo(‘name’);
}
?>
<title><?php echo $blog_title; ?></title>

Explanation. The 1st part before the first “}” sets the title for the homepage. It’s the blog name plus the description separated by a dash “-“. The 2nd part sets the title for your posts, and that’s the post title plus the blog name, separated with a dash. The 3rd part sets the title for your category pages, which is the category name plus the blog name, separated with a dash. The last part sets the title for your pages, which is the page title plus the blog name, separated with a dash.

This is just one example. When it comes to code, there are many ways to accomplish the same task. Also, there are different ways to format the title, so you may have to play around with the code a bit until you get what you want.

One thought on “How to Automatically Add Meta Title Tags to Your Posts and Pages in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.