Search code examples
phpregexmagentoseocanonical-link

Was my SEO firm trying to sabotage my website?


I found this code in my head.phtml after my SEO firm did a 1 time audit on my site. Were they removing canonicals from paginated content hoping It would hurt my rankings so I'd get a monthly package with them???

$cssjshtml=$this->getCssJsHtml();

if(isset($_GET['p']) && $_GET['p']>1)
{

    $strtofind='/<link[^>]rel="canonical" href=".*"[^>]*>/i';

    //preg_replace('/(<div.*?class="name"[^>]*>)(.*?)(<\/div>)/i', '$1$3', $string);
    $html=preg_replace($strtofind, '', $cssjshtml);

    //echo '<pre>';$strtofind
        //print_r($strtofind);
    ///echo '</pre>';   
    //$cssjshtml=;

    echo $html;
}
else
{
    echo $this->getCssJsHtml();
}

Could there be any legitimate reason for doing this?

Original head only contains the echo $this->getCssJsHtml(); part


Solution

  • Case 1 : That may be a mistake done by the SEO firm: rel=canonical to the first page of a paginated series

    Imagine that you have an article that spans several pages:

    example.com/article?story=cupcake-news&page=1
    example.com/article?story=cupcake-news&page=2
    and so on
    

    Specifying a rel=canonical from page 2 (or any later page) to page 1 is not correct use of rel=canonical, as these are not duplicate pages. Using rel=canonical in this instance would result in the content on pages 2 and beyond not being indexed at all. Source

    Case 2 : That may not be a mistake considering the recent developments. When we talk about putting paginated content accross. We do it using

    <link rel="next" href="http://www.example.com/article-part2.html">
    

    on the first page and then using

    <link rel="prev" href="http://www.example.com/article-part1.html">
    <link rel="next" href="http://www.example.com/article-part3.html">
    

    on the subsequesnt pages. Check your code for a presence of this kind of stuff. Source

    In case you are seeing the first case then be prompt and get your source code changed right away.