: 2 URL's pointing to one website with unique canonical url's I have 2 domains submitted to Google that both point to my WordPress site. I am using Yoast SEO plugin to take care of the basic
I have 2 domains submitted to Google that both point to my WordPress site. I am using Yoast SEO plugin to take care of the basic SEO metadata for the website.
When I view the source for each url I have noticed that the canonical url's are unique to each website, for example I have 2 urls:
example.com <link rel="canonical" href="http://example.com/" /> example2.com <link rel="canonical" href="http://example2.com/" />
How would it be possible for me to set the canonical url for both to be pointing to example.com? It's just one website with both url's pointing to it so this seems a little strange to me.
Many Thanks
More posts by @Speyer207
1 Comments
Sorted by latest first Latest Oldest Best
Sounds like the easiest method without having to edit Yoast SEO PHP code directly would be to disable canonicals being handled by Yoast SEO all together.
Disable it like so:
SOURCE
Filter to Disable Canonical URLs
add_filter( 'wpseo_canonical', '__return_false');
Steps to Disabling Yoast Canonicals
You can disable canonical links being added to the HEAD by following these simple steps:
Login to WordPress
Hover over Appearance
Click Editor
Find Theme Functions (functions.php)
Add the code found above to a new link within your functions.php
Then I'd opt to use canonicals without having to use a WordPress plugin, like so:
SOURCE
Universal PHP Code for Canonical URLS
Below is the code that you need to add within the head of your theme template:
<link rel="canonical" href="https://www.bybe.net<?php echo $_SERVER['REQUEST_URI'];?>">
Obviously you will need to replace bybe.net with your own domain.
Adding canonical Links in WordPress
Below are a few easy steps that will have you up and running with WordPress canonical URLS in no time at all, and without a plugin.
Login to WordPress
Hover over Appearance
Click Editor
Find Theme Header (header.php)
Add the Universal PHP Code for Canonical URLS found above within the HEAD section of your theme header file.
The PHP code $_SERVER['REQUEST_URI'] will get the relative path so you only need to replace the domain before it, then you are set to go.
Should you or anyone else stubble across this post and want to have a few pages internal canonicals and a few externals then this can be be done using:
is_page()
is_single(), not to be confused with a Facebook relationship status, it means post.
You should also make good use of IF and ELSE, should you have multiple pages or posts.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.