Open gleysen opened 1 year ago
I also really need this functionality for the same purpose. I have multiple language and regional versions of our sites with some unique content and some content copied using distributor and then translated. Previously, the canonical URL was supposed to be sufficient. But now we need these hreflang tags and you need to have all alternative versions listed on every version.
This should be relatively simple, but I'm not experienced enough to know exactly how best to do it. I made a start here:
add_action('wp_head', 'add_hreflang');
function add_hreflang() {
if (distributor_get_original_post_link($post->ID)) {
?>
<link rel="alternate" href="<?php echo distributor_get_original_post_link($post->ID); ?>" hreflang="<?php ?>" />
<link rel="alternate" href="<?php echo get_permalink(); ?>" hreflang="<?php echo str_replace('_','-',get_locale()); ?>" />
<?php
}
};
That will add the tags of the source and the destination to the destination post. But I don't know how to get the locale of the source and I don't know how to get this to apply to the source post either.
With Muhammad's fix I can get this functionality working but only with pushed posts and only to the destination site, not the source site.
Modified my snippet to be added in functions.php
add_action('wp_head', 'add_hreflang');
function add_hreflang() {
if (distributor_get_original_post_link()) {
?>
<link rel="alternate" href="<?php echo distributor_get_original_post_link(); ?>" hreflang="<?php echo distributor_get_original_site_lang(); ?>" />
<link rel="alternate" href="<?php echo get_permalink(); ?>" hreflang="<?php echo str_replace('_','-',get_locale()); ?>" />
<?php
}
};
@CptCrunchy24 click here to get commit for pulled post.
PR is #1019
This newer version is working better. Both pushed and pulled posts are correctly including the alternate links. Now we need to figure out how to add the alternate links to the original post as well.
Can we get the distributed URLs and language codes using the 'dt_connection_map' post meta? It contains the post IDs of all distributed posts. Can we get the canonical URL from the destination site using the post ID?
I think I'm missing something here.
I understand hreflang
is more appropriate for a post on an equivalent but translated site (wordpress.org vs fr.wordpress.org).
What I am having trouble understanding is the use case for Distributor, as the original text of the post is pushed/pulled in the original language. In the Distributor case, it seems that hreflang
could promise a translation that does not exist.
@gleysen Is there a step that I am missing?
@peterwilsoncc hreflang is used mostly for different languages indeed, however in my case it's also used for 2 sites that are both in Dutch. One in Belgian Dutch .. site.be , and the other one in Dutch for the Netherlands... site.nl. Both are Dutch, but when people search in Google I want the Belgian site to be shown for people from Belgium and the .nl site to be shown to people from the Netherlands. ... and the French version for people that are from Belgium but use the French version...etc. So that's where the hreflang comes in... In the meanwhile I've switched to WP All Export, with some custom snippet to do the exports of my custom post types ... but would be nice if this was included in Distributor, so I could use that for syncing pages and posts that don't need any change between both Dutch sites.
The use for distributor when dealing with different languages is also that it means we can produce content on one site with an English editor and then push it to a different language site where a translator will translate the post and publish it. Distributor speeds up the process and potentially automate the hreflang tags.
This means we can use a translator who just translates the text and doesn't touch any images, formatting etc. and we're good to go.
Thanks both for clarifying your use cases.
Describe your question
I'm integrating Distributor in a setup where I have a domain.be that pusches articles to a domain.fr site, and I want to use hreflang tags instead of the standard canonical tags. Anyone try this already? Or can give me some code tips on where to start with making these adaptations?! (basically, on the .fr pages, there needs to be an hreflang link to the .be page, and visa versa, for SEO purposes and so that Google will rank the right page in a country.)
Thx for your help!
G.
Code of Conduct