Canonical tag for mobile subdomain at WordPress

Some of my clients have  mobile version of website. With one of them  I found terrible issue – they got lot’s of duplicated content because of incorrect canonical tags. So for  instance yahoo.com and m.yahoo.com, it obvious that that the content will be the same but the design for m.yahoo.com will be optimized for mobile platforms. It’s nothing wrong in term of IT, but it’s suicide for SEO approach.

To avoid duplicate content issues, we’re using rel=”canonical” to indicate which post is the original and which is the duplicate.

My client’s website is sevelina.com with mobile subdomain m.sevelina.com, both of them host same content. How to avoid Google penalty for duplicated content? They suggest using rel=”canonical”. It’s good solution for separate websites, but website consists of only one wordpress installation and mobile users receive same content by help of specially designed mobile theme. All this stuff displaying at mobile subdomain. So, how to display canonical tag to subdomain?

1. First of all you need to disable rel=”canonical” from the Yoast plugin:

add_filter( 'wpseo_canonical', '__return_false' );

2. Let’s do some magic and generate new canonical tag for your subdomain:

remove_action( 'wp_head', 'rel_canonical' );
add_action( 'wp_head', 'my_rel_canonical' );

function new_rel_canonical() {
if ( !is_singular() )
return;
global $wp_the_query;
if ( !$id = $wp_the_query->get_queried_object_id() )
return;
$link = get_permalink( $id );
$link = str_replace( 'm.sevelina.com', 'sevelina.com', $link );
echo "<link rel='canonical' href='$link' />\n";
}

It’s cool, right now website of Sevelina have got mobile subdomain and have canonical tag to the main domain.

1 Comments

  1. Shady stock brokers will try to sell speculative stocks to clients who have expressed preference
    in investing in low-risk, steady growth stocks that have less risk
    of sustaining capital loss. Several cleaning
    methods are available for different types of carpets.
    You can also use the water from cookibg your potatoes here rather than just
    plain water.

    Reply

Leave a Reply to analytics/goo.gl/r8zBDz/day Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.