Custom Fields - SEO Your Title Tag


/ Published in: PHP
Save to your folder(s)

Search Engine Optimisation, or SEO is something that a lot of bloggers get obsessed about, whilst others think it’s a load of rubbish. I’m halfway between the two – whilst I believe that you can change certain things to better SEO your content, such as adding H1, H2 etc tags in the appropriate places, I personally don’t think you should get too carried away with it. One of the things you can do though is change your title tag, and this custom field trick will let you set a custom field and it’ll appear as your title tag. Add the code below to your header.php file:


Copy this code and paste it in your HTML
  1. <?php $title = get_post_meta($post->ID, 'post-img', true);
  2. if ($postimageurl) {
  3. ?>
  4. <title><?php echo $title; ?></title>
  5. <?php } else { ?>
  6. <title><?php wp_title(''); ?> | <?php bloginfo('name'); ?></title>
  7.  
  8. <?php } ?>
  9.  
  10.  
  11. //Then, you can create a custom field <title> and it’ll appear as your title! If no custom field is set then a blog-standard title is displayed.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.