Skip to content

Hreflang tag shouldn't be outputted when a translation is connected but unpublished #173

Open
@nowori

Description

@nowori

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions