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 tag shouldn't be outputted when a translation is connected but unpublished #173

Open
nowori opened this issue Jun 1, 2021 · 0 comments

Comments

@nowori
Copy link
Contributor

nowori commented Jun 1, 2021

Hey there,

Currently, MSLS outputs the homepage URL for hreflang tags, when a page is connected but not published. This seems to be bad practice, which makes sense as hreflang tags are supposed to be reciprocal, that is they should all reference each other on their respective page, which doesn't happen when we output the homepage hreflang on a specific page = it wouldn't be reciprocated on the homepage.

Difficult to find references on the topic but here are some:
https://webmasters.stackexchange.com/questions/118439/use-of-rel-alternate-on-multilingual-site/118455
https://cognitiveseo.com/blog/17150/multi-language-website-mistakes/

I am not proposing a pull request as I'm unsure how to best cater for this.

It seems that the goal of this code was to implement this scenario:

if ( is_null( $url ) ) {
continue;
}

But it seems it is never null because of:

return '' != $postlink ? $postlink : home_url( '/' );

But I guess this is not where this should be fixed as it is probably used to output the language switcher, amongst other things. Would appreciate if you could have a look.

For now and if others want to fix this behavior, this is how I've implemented it:

add_filter( 'mlsl_output_get_alternate_links', function( $url, $blog ) {

	if ( !is_front_page() && $url === trailingslashit( $blog->siteurl ) )
		return null;
	else
		return $url;

}, 10, 2 );

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant