Canonical Link - new Google/Yahoo/Microsoft feature for duplicate content pag

Started by Antechinus, February 15, 2009, 07:05:46 PM

Previous topic - Next topic

Antechinus

Regex put us onto this and the team gives it a unanimous thumbs up. It can be applied to any theme or any version of SMF and will improve your search rankings.

Quote from: regularexpression on February 15, 2009, 04:07:08 PMI'm keen to see SMF get ahead of the curve with this, as it is going to be seen as major potatoes.

A new feature supported by Google, Microsoft and Yahoo to help rid the web of duplicate content pages in search engines.
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html


This is great news for SMF as it will help with a lot of duplicate content links.

To Themes/default/index.template.php I added

// Google, Yahoo, Microsoft - canonical tag to help with duplicate content
if (!empty($context['current_topic']))
echo '
<link rel="canonical" href="', $scripturl, '?topic=', $context['current_topic'], '.', $context['start'], '" />';
elseif (!empty($context['current_board']))
echo '
<link rel="canonical" href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], '" />';


This will help a lot with duplicate content pages, not just for existing no-indexed pages like .msg/prev-next links, but also at least two outstanding bug reports for RC1. If canonical tag is implemented, the bug reports can be closed.

Incorrect board/topic links (eg missing a start parameter index.php?topic=1234)
http://dev.simplemachines.org/mantis/view.php?id=3000

SEF vs Non-SEF links.
http://dev.simplemachines.org/mantis/view.php?id=2970

If the forum is using SEF links, but google follows a backlink that uses non-sef format, the canonical one fixes it.

So that's it.  In contrast to my two bug reports which have been moved to 2.1 (and not easy to fix), this is something which literally will take two seconds and should have great benefit to our forums now.

Can we add this to the bugtracker for 2.0 please?

As noted the code goes in your index.template.php in the <head> section.

Attached are example files for the 1.1.8 and RC1 default themes. These will need to be re-named to index.template.php before use. A mod package will probably be along shortly.


ETA: Ok, code is updated to a better version. Files have been fixed and reloaded. Go with this:

    // Google, Yahoo, Microsoft - canonical tag to help with duplicate content
if (!empty($context['current_topic']))
        echo '
    <link rel="canonical" href="', $scripturl, '?topic=', $context['current_topic'] . (!empty($context['start']) ? '.' . $context['start'] : '.0') . '" />';
    elseif (!empty($context['current_board']))
        echo '
    <link rel="canonical" href="', $scripturl, '?board=', $context['current_board'] . (!empty($context['start']) ? '.' . $context['start'] : '.0') . '" />';



Bancherd

Thanks.  :D   

Where is "start" defined?  I am getting errors. with smf1.1.8.


Advertisement: