Plugin Author
DAEXT
(@daext)
Hello Deon,
Yes, using this plugin in your case is appropriate.
On your blog you have to add the hreflang data for the 10 translated articles using the Connections menu. Then you have to repeat the process in the subdomains to achieve hreflang link back compliance.
Thread Starter
Deon
(@deon-b)
Hi,
Thank you.
So I will just create connections on each subdomain, for each URL, including home page and such.
Will this method basically add some code in my functions.php file? (so technically I could just add this to my PHP) and would be the same?
function add_hreflang_tags() {
if (is_page()) {
global $post;
// Define hreflang relationships for this domain
$translations = array(
'how-to-eat-peach' => array(
'en' => 'https://website.com/how-to-eat-peach/',
'it' => 'https://it.website.com/come-mangiare-la-pesca/',
),
'another-article' => array(
'en' => 'https://website.com/another-article/',
'it' => 'https://it.website.com/un-altro-articolo/',
),
);
$current_url = get_permalink($post);
// Loop through translations to find matches
foreach ($translations as $key => $langs) {
if (in_array($current_url, $langs)) {
foreach ($langs as $lang => $url) {
echo '<link rel="alternate" hreflang="' . $lang . '" href="' . $url . '" />' . "\n";
}
break;
}
}
}
}
add_action('wp_head', 'add_hreflang_tags');
https://prnt.sc/YtDVbtc87lSD
Is this in the screenshot correct?
Is there any way to double check all is set up correctly in the end?
Thread Starter
Deon
(@deon-b)
Hi,
Thanks, I don’t know why the image is not showing. Can you check this?
View post on imgur.com
Plugin Author
DAEXT
(@daext)
Hello Dean,
Scripts are for languages that have different scripts (like Chinese). English does not have alternative scripts.
The locale is for configuring geographical targets. E.g. English for users in US or English for users in Canada.
Note that for questions on different subjects I recommend to open new dedicated forum threads.
Hope this helps.
Thread Starter
Deon
(@deon-b)
Hi, thanks,
I think this is the same thread, same line of question for me.
If you see in the image I attached, the first 3 fields, and the red things I wrote, is that the correct way of using this plugin?
On German subdomain:
URL to connect: Here URL from site where plugin is installed, example: de.website.com/house/
URL 1: Here URL from main site in english, example: website.com/house/
Language 1: Here language from main site in english, example: English.
URL to connect: Here URL from site where plugin is installed, example: de.website.com/house/
URL 2: Here URL from second site in french, example: fr.website.com/house/
Language 2: Here language from main site in french, example: French.
On English main domain:
URL to connect: Here URL from site where plugin is installed, example: website.com/house/
URL 1: Here URL from subdomain in german de.website.com/house/
Language 1: German
URL to connect: website.com/house/
URL 2: fr.website.com/house/
Language 2: French
On French subdomain:
URL to connect: fr.website.com/house/
URL 1: website.com/house/
Language 1: English
URL to connect: fr.website.com/house/
URL 2: de.website.com/house/
Language 2: German
Like this is correct?
Plugin Author
DAEXT
(@daext)
Hello Deon,
The URL to Connect field is where you want to add the hreflang tags.
The URL 1, URL 2, etc. are the reference to the alternate pages. These should be adde based on the Google guidelines: https://developers.google.com/search/docs/specialty/international/localized-versions
A few implementation examples with Hreflang Manager:
For a feedback I recommend sharing a public URL with hreflang implemented. So that the tags and related link back can be checked.