Home / Search Marketing / Yoast SEO: Canonical URLs on a Site with Optional SSL

Yoast SEO: Canonical URLs on a Site with Optional SSL

When we moved our site over to Flywheel, we didn’t force everyone into an SSL connection (the https:// url that ensures a secure connection). We’re still undecided on this. We may ensure that form submissions and the ecommerce portion are secure, but not sure about just the average article to read.

With that in mind, we realized that our canonical links were showing up both secure and insecure. I’ve not read a lot on the topic, but that seems that it could be problematic if Google is treating each path separately. Indeed, within Webmasters, we had to register the secure site separately so I can only guess that it would cause confusion.

What is a Canonical Link?

A canonical link element is an element in the head section of an HTML page (invisible to users) that guides search engines to the preferred version of a web page. This is an essential element when optimizing your site for search engines since you want to ensure any authority passed through links goes to the appropriate URL. The vast majority of content management systems produce multiple paths to identical content. Without a canonical to define the appropriate path, your authority could be split between multiple paths to the same content.

In reviewing the Yoast SEO plugin knowledge base, the plugin simply pulls the permalink through WordPress’ standard function. In other words, if you’re on a secure page, it’s going to list the https path, if you’re not – it’s going to list the http path. Ugh.

Within our theme’s functions.php file, and using Yoast’s canonical filter wpseo_canonical, we added the following function to force all canonical links to the secure URL:

function mtb_canonical_ssl($url) {
   $url = preg_replace("/^http:/i", "https:", $url);
   return $url;
}
add_filter( 'wpseo_canonical', 'mtb_canonical_ssl' );

Now, regardless of which path a user goes to or how the Google crawler captures the canonical, it will only show up as the secure page with the https:// URL path. The Yoast plugin used to have the option to define this, but it appears it was depricated from the plugin.

Get Affordable WordPress Help Now

About Douglas Karr

Douglas Karr is the founder of The Marketing Technology Blog and recognized MarTech expert. Doug is a Keynote and Marketing Public Speaker. He's the CEO of DK New Media, an agency specializing in assisting marketing technology companies with their inbound marketing - leveraging social media, blogging, search engine optimization, pay per click and public relations. He's assisted SaaS companies like Angie's List, GoDaddy, Salesforce, Webtrends, and SmartFOCUS with their digital marketing and product strategies. Douglas is also the author of Corporate Blogging for Dummies.

Check Also

Key SEO Strategies 2016

7 SEO Key Strategies You Should be Deploying in 2016

A few years ago, I wrote that SEO was dead. The title was a bit …

One comment

  1. its not working elev40 child theme

Leave a Reply