[wp-trac] [WordPress Trac] #63807: Add Native Support for Hreflang Tags in WordPress Core
WordPress Trac
noreply at wordpress.org
Sun Aug 10 23:09:26 UTC 2025
#63807: Add Native Support for Hreflang Tags in WordPress Core
-------------------------+-------------------------
Reporter: henrykarl | Owner: (none)
Type: enhancement | Status: closed
Priority: normal | Milestone:
Component: I18N | Version:
Severity: normal | Resolution: maybelater
Keywords: | Focuses:
-------------------------+-------------------------
Changes (by peterwilsoncc):
* status: new => closed
* resolution: => maybelater
* component: General => I18N
* severity: major => normal
* milestone: Awaiting Review =>
Comment:
Hi @henrykarl and welcome to trac!
For user facing features, WordPress aims to design for the majority of
websites with the guideline that
[https://wordpress.org/about/philosophy/#:~:text=Clean%2C%20lean%2C%20and%20mean
new features will be used by 80% of end users].
While the majority of sites use a language pack other than US English,
they're typically single language sites that don't have a use for
`hreflang` tags so I think this is a feature that remains best in plugins.
At its absolute simplest, I think a plugin could use a custom taxonomy and
the `wp_head` action to output the header tag. Something like the
following, untested, code:
{{{#!php
<?php
function really_simple_hreflang() {
if ( ! is_singular() ) {
return;
}
$permalink = get_permalink();
$langs = wp_get_object_terms( get_post_id(), 'rsh_langs' );
foreach( $langs as $lang ) {
$term_domain = get_term_meta( $lang->term_id,
'rsh_domain', true );
$lang_permalink = preg_replace( '/:\/\/(.*)\//U',
"://{$$term_domain}/", $permalink );
$esc_lang_permalink = esc_url( $lang_permalink );
echo "<link rel='alternate' hreflang='{$term->slug}'
href='{$esc_lang_permalink}' />"
}
}
add_action( 'wp_head', 'really_simple_hreflang' );
}}}
I've closed this ticket off as maybelater, which means that the feature
can be reconsidered if the need for native support of the `hreflang` tags
become more widely used in the future.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63807#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list