Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    last time I checked, <link rel="alternate" href="https://example.com" hreflang="x-default"> was to be used for a website that either does not target a specific language/region, or does not include content at all. In the latter case, the website is only used for redirection.
    That’s why we didn’t include this so far.

    If you want to do this, say for site with ID 42, you can do this like so:

    add_action( 'wp_head', function () {
    
        if ( 42 !== get_current_blog_id() ) {
            return;
        }
        ?>
        <link rel="alternate" href="<?php echo esc_url( home_url() ); ?>" hreflang="x-default">
        <?php
    } );

    Put the above code in a MU plugin, or to the according theme’s functions.php file.

    Best regards,
    Thorsten

    Thread Starter usertn

    (@usertn)

    Hi Thorsten,

    Thank you for your reply.

    I puted your code, but the result is not what Google wants.

    – All hreflang codes should be same on all linked websites.
    <link rel="alternate" href="https://example.com" hreflang="x-default"> must appear on the main website and on localized websites, not only on the main website.

    For example, if there are 3 websites (www|fr|es), there should be the same 4 lines on each :
    <link rel="alternate" href="https://www.example.com" hreflang="x-default">
    <link rel="alternate" href="https://www.example.com" hreflang="en">
    <link rel="alternate" href="https://fr.example.com" hreflang="fr">
    <link rel="alternate" href="https://es.example.com" hreflang="es">

    – The URL should always be that of the linked page of the main website (not the hompepage).

    For example, on the webpage https://fr.exemple.com/page/ :
    <link rel="alternate" href="https://www.example.com/page/" hreflang="x-default">
    <link rel="alternate" href="https://www.example.com/page/" hreflang="en">
    <link rel="alternate" href="https://fr.example.com/page/" hreflang="fr">
    <link rel="alternate" href="https://es.example.com/page/" hreflang="es">

    – In my multisite network, some independant websites are not connected to others with multilingual press. No new tag hreflang=”x-default” should appear on those independant websites. Only on linked websites with the plugin.

    Thank you for your help.

    Regards.

    Ah, okay, then it’s this:

    add_action( 'wp_head', function () {
    
    	$related_sites = mlp_get_available_languages_titles();
    	unset( $related_sites[ get_current_blog_id() ] );
    
    	if ( ! $related_sites ) {
    		return;
    	}
    	?>
    	<link rel="alternate" href="<?php echo esc_url( get_home_url( 42 ) ); ?>" hreflang="x-default">
    	<?php
    } );

    In the example, I still used ID 42 to indicate your main site. Adapt that as necessary.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘hreflang x-default’ is closed to new replies.