Wordpress

How To Create Title Tag In WordPress

How To Create Title Tag In WordPress

Depending on what page you are on you need to make sure that the title tag is different on each page. This is important for SEO because you can’t have pages with the same title tag.

As WordPress is a CMS you use the same header section on each page so you need to add some logic to make sure they are different depending on what page you are on.

Here is a WordPress snippet that you should add to the head tag of your theme.

Put this code between the title tags.


<title>
<?php
if (function_exists('is_tag') && is_tag()) { //tag page
single_tag_title("Tag Archive for &quot;"); echo '&quot; - '; }
elseif (is_archive()) { //Archive page
wp_title(''); echo ' Archive - '; }
elseif (is_search()) { //Search page
echo 'Search for &quot;'.wp_specialchars($s).'&quot; - '; }
elseif (!(is_404()) && (is_single()) || (is_page())) { //Single page
wp_title(''); echo ' - '; }
elseif (is_404()) { //404 page
echo 'Not Found - '; }
if (is_home()) { //Home page
bloginfo('name'); echo ' - '; bloginfo('description'); }
else { //Blog Page
bloginfo('name'); }
if ($paged>1) { //Paged Search page
echo ' - page '. $paged; }
?>
</title>

This checks to see what type of page you are on and will change the title depending on this.

From: http://www.paulund.co.uk/how-to-create-title-tag-in-wordpress

With many thanks.

Leave a Comment

Your email address will not be published.