Add link rel="prev/next" to your blog

Google has been trying to improve the way it detects duplicate content on a website. URLs with parameters, such as the ones used for pagination, are tricky. You have the option to add a link tag to help Google identify this content. To read more about this check out the blog post in the Google webmaster blog.

To implement this in a Joomla template you can add the code in the overrides. For example you can open root/templates/your_template/html/com_content/blog.php. Inside it add this code:

// Add rel=prev/next
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
$doc =& JFactory::getDocument();
$pagdata = $this->pagination->getData();
if($pagdata->next->link){
 $doc->addHeadLink( $pagdata->next->link, 'next');
}
if($pagdata->previous->link){
 $doc->addHeadLink( $pagdata->previous->link, 'prev');
}

The variable $pagdata contains all the information about the pagination for the current page. We simply make a check for a next or previous page link. If there is one it means the page with other items exists so we can add the link tag. We do this with the addHeadLink function.

Rate this item
(2 votes)
Tagged under

14 comments

  • Comment Link Halley Wednesday, 01 May 2013 11:56 posted by Halley

    Hi there, I enjoy reading through your article post.
    I like to write a little comment to support you.

  • Comment Link Http://Www.Slictraining.Org.Uk Monday, 15 April 2013 14:37 posted by Http://Www.Slictraining.Org.Uk

    Simply want to say your post is just as amazing.

  • Comment Link learn more Wednesday, 03 April 2013 07:48 posted by learn more

    Have you thought to add more pictures and videos?
    I think it might spruce this content up a little bit more.
    Not to imply it's bad, but I am a visual kind of man. No big deal, simply a idea.

  • Comment Link Antony Wednesday, 13 February 2013 08:11 posted by Antony

    Keep this going please, great job!

  • Comment Link Benny Tuesday, 29 January 2013 20:29 posted by Benny

    My brother suggested I might like this web site. He was totally right.

    This post actually made my day. You cann't imagine just how much time I had spent for this information! Thanks!

  • Comment Link Monisha Vohra Tuesday, 15 January 2013 19:23 posted by Monisha Vohra

    It's nice to see this site is finally getting the attention that it deserves Keep up the fantastic work.

  • Comment Link Harlan Monday, 20 August 2012 00:03 posted by Harlan

    Great blog here! Also your website loads up very fast!
    What web host are you using? Can I get your affiliate link to your host?

    I wish my site loaded up as quickly as yours lol

  • Comment Link homepage Thursday, 05 July 2012 01:36 posted by homepage

    Your style is very unique in comparison to other folks I have
    read stuff from. Thank you for posting when you have
    the opportunity, Guess I'll just bookmark this web site.

  • Comment Link Demente Saturday, 30 June 2012 07:20 posted by Demente

    @serena This hasn't been tested in 1.5 but it should work, eventually with a few modifications. If addLink already exists you only have to check that the data returned by getData is the same. Try echoing $pagdata->next->link or using print_r($pagdata->next->link). Note that you don't have to replace anything in your original file.

  • Comment Link serena Friday, 29 June 2012 08:48 posted by serena

    Hi! I'm trying to make this change in a joomla 1.5 site. The function AddHeadlink is defined in the libraries but I haven't found the code to sobstitute in blog.php. someone said if($pagdata->previous->link) but I haven't find it in my file. could you help me?

Leave a comment