![]()
In this tutorial I’ll demonstrate how using PHP, you can display different tile tags depending on what page is displayed to the user. This is an example of how you can customise your Wordpress theme to suit your needs.
Say that you are on the home page and you want to display in the title tag the name of the website and the description. Now you navigate away from the home page and move to a category page. You want to display in the title tag the category and the name of the website without the description for sharing purposes (sharing the link on Twitter for example). Finally you are inside a post page and you want to display the name of the post with the name of the website only. How do you do it?
Step 1
Go to your header.php file within the template and locate the <title></title> tags. Next, there are three types of pages we need to keep in mind:
- Post page
- Category page
- Home page
Post Page
Check if the page is a post page then display the title of the post and the name of the blog (or whatever else you want to display). Below is the code to add inside the title tag after the given code above:
<?php if ( is_single() ) { wp_title(‘ ‘); ?> » <?php bloginfo(‘name’); ?>
Category Page
If the page isn’t a post page, we need to check if the page is a category page. If it is, display the category title and the name of the blog (or whatever else you want to display). Below is the code to add inside the title tag after the given code above:
<?php } elseif (is_category() ) {single_cat_title(); ?> » <?php bloginfo(‘name’); ?>
Home page
If the page is none of the above, then it means that it is a home page. Display the name of the blog and the description of it (or whatever else you want to display). Below is the code to add inside the title tag after the given code above:
<?php } else { ?><?php bloginfo(‘name’); ?> » <?php bloginfo(‘description’); ?><?php }?>
Conclusion
So the complete title tag should look like this:
<title><?php if ( is_single() ) { wp_title(‘ ‘); ?> » <?php bloginfo(‘name’); ?><?php } elseif (is_category() ) {single_cat_title(); ?> » <?php bloginfo(‘name’); ?><?php } else { ?><?php bloginfo(‘name’); ?> » <?php bloginfo(‘description’); ?><?php }?></title>
Of course, you could change the title tag to suit your needs; this is just a demonstration what can be achieved.
Also, check out the Wordpress help sheet to see more PHP snippets and codes helping you customise a Wordpress theme easily!
Hope you have fun with it!
Leave your comments in the comments section below, if you have any questions.
Source Files are unavailable for this tutorial! No Source Files








After reading you blog, Your blog is very useful for me .I bookmarked your blog!
Wishes your valentine day to be joyful!
Trackbacks