Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hreflang integration? #1001

Open
1 task done
gleysen opened this issue Jan 10, 2023 · 10 comments · May be fixed by #1019
Open
1 task done

hreflang integration? #1001

gleysen opened this issue Jan 10, 2023 · 10 comments · May be fixed by #1019
Assignees
Labels
type:question Further information is requested.

Comments

@gleysen
Copy link

gleysen commented Jan 10, 2023

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

  • I agree to follow this project's Code of Conduct
@gleysen gleysen added the type:question Further information is requested. label Jan 10, 2023
@CptCrunchy24
Copy link

CptCrunchy24 commented Feb 17, 2023

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.

muhammadtvk added a commit to muhammadtvk/distributor that referenced this issue Feb 21, 2023
@muhammadtvk muhammadtvk linked a pull request Feb 21, 2023 that will close this issue
@CptCrunchy24
Copy link

CptCrunchy24 commented Feb 21, 2023

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
}
};

@muhammadtvk
Copy link

@CptCrunchy24 click here to get commit for pulled post.

@muhammadtvk
Copy link

PR is #1019

@CptCrunchy24
Copy link

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.

@CptCrunchy24
Copy link

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?
image

@peterwilsoncc
Copy link
Collaborator

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?

@gleysen
Copy link
Author

gleysen commented Mar 6, 2023

@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.

@CptCrunchy24
Copy link

CptCrunchy24 commented Mar 6, 2023

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.

@peterwilsoncc
Copy link
Collaborator

Thanks both for clarifying your use cases.

@jeffpaul jeffpaul linked a pull request Mar 20, 2023 that will close this issue
@jeffpaul jeffpaul added this to the Future Release milestone Mar 20, 2023
@jeffpaul jeffpaul moved this from Incoming to In Review in Open Source Practice Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Further information is requested.
Projects
Status: Code Review
Development

Successfully merging a pull request may close this issue.

5 participants