17 Jun

Canonical url trailing slash missing for homepage – WordPress & Yoast

wordpress canonical trailing slash

When you install WordPress in a sub directory Example: ‘blog’, the canonical link should be: www.example.com/blog/. But Canonical url trailing slash will be missing for homepage. Yoast will show the home page canonical tag, without having a trailing slash like this : www.example.com/blog

All pages will show the canonical URLs as having a trailing slash except the home page. Yoast WordPress SEO plugin gives canonical url and sitemap url as www.example.com/blog which is incorrect. So the problem is, Google will index home page (www.example.com/blog/) without a trailing slash. The SEO plugin should put the trailing slash in the canonical url and in the sitemap when the site is in a subdirectory.

Solution:

There is no need for editing .htaccess file. You can fix this issiue from WordPress admin panel.
Wordpress admin panel -> Plugins -> Editor. Select WordPress SEO from the right top of the page. Find and select the file “wordpress-seo/frontend/class-frontend.php” from the right side of files list.

In that file, find this code: ” $canonical = home_url();
Update that code like this : ” $canonical = home_url(‘/’);

Done !!

Canonical url trailing slash will be showing for home page (www.example.com/blog/)

Sanju
Follow me

About Sanju

I’m Sanjunath.S from Mumbai, India. I like web technologies, traveling & history. I have 11+ years of experience in web technologies like HTML 5, CSS 3, JavaScript, Bootstrap, and PHP.




Pay with PayPal
Translate »