Web Design that taps into the haromny and vision of your dreams.

How to Determine Paged Comments in WordPress 2.7

WordPress Paged Comments

Written By on in PHP

274 words, estimated reading time 2 minutes.

Wordpress 2.7 introduced paged comments out the box, however, you will probably be wanting to prevent search engines from indexing these pages to prevent duplicate content. You may also just wish to determine if a user is viewing a paged comments.

The new update to WordPress will allow your comments to be paged, that is show comments 1-50 on page 1, 51 - 100 on page 2 etc, but it will also have the effect of duplicating your content on many pages. It is common practice to exclude certain pages from being index by search engines by using the "robots=nofollow" meta attribute. With Wordpress 2.7 if you have multiple comment pages, all pages will be indexed any you may fall foul of the duplicate content filter, and you could be heavily penalised by Google in the forthcoming Panda update. You can prevent this with a little function which will identify a comment page and a little change to the header.

The function for comment paged detection should be placed in the functions.php in your themes folder.

function is_comments_paged()
{
  $pos = strpos($_SERVER['REQUEST_URI'], "comment-page");
 
  if ($pos === false) 
  {
    return false;
  } 
  else 
  {
    return true;
  }
} 

Its quite simple really, it just looks for 'comment-page' in the URL.

In your header you will need to add (or modify if you have a similar section) this code. For clarity, I have added the above function call on a different line, but you can just merge it with the first if statement.

<?php
if((is_home() || is_single() || is_category() || is_page()) && (!is_paged())) 
{
  if (is_comments_paged())
    echo '  <meta name="robots" content="noindex,follow" />';
  else
    echo '  <meta name="robots" content="index,follow" />';
} 
else 
{
  echo '  <meta name="robots" content="noindex,follow" />';
}
?>

Last updated on: Thursday 22nd June 2017

 

Comments

There are no comments for this post. Be the first!

 

Leave a Reply

Your email address will not be published.





If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me