Home›Support›English Support›[Waiting for user feedback] remove outgoing hreflang annotation from some URL (noindex URLS)
[Waiting for user feedback] remove outgoing hreflang annotation from some URL (noindex URLS)
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
WordPress 6.7 has introduced a new issue that impact translations, please update WooCommerce and WPML to the latest versions before you report issues. More about this here - https://wpml.org/errata/php-error-wp-6-7-notice-function-_load_textdomain_just_in_time-was-called/
Background of the issue:
I am trying to manage hreflang tags on my website, hidden link, to ensure they do not conflict with noindex meta tags. Hreflang tags are used to indicate language-specific versions of a page to search engines, but if a page has a noindex tag, it should not be indexed. I want to remove hreflang tags from URLs that are marked as noindex, especially for TAG pages, to avoid confusing search engines.
Symptoms:
The SEO system detected a critical issue where outgoing hreflang annotations are pointing to noindex URLs, which could lead to search engines ignoring the hreflang tags.
Questions:
How can I remove hreflang tags from my no-indexed URLs, specifically TAG pages?
I understand what you're looking for. If you want a specific tag or taxonomy with a `noindex` directive to not have the hreflang tag, it is possible to achieve that using the `wpml_hreflangs_html` filter hook with a callback function to remove the hreflang. For example, check the code below, which might help remove the hreflang if the tag or taxonomy has the `noindex` directive.
add_filter( 'wpml_hreflangs_html', function( $hreflang ) {
// Check if the current page is a taxonomy page (tag, category, or other taxonomy)
if ( is_tag() || is_category() || is_tax() ) {
// Get the robots meta using the wp_robots filter and check if 'noindex' is set
$robots_meta = apply_filters( 'wp_robots', [], get_queried_object() );
// Check if 'noindex' is in the robots meta array
if ( is_array( $robots_meta ) && in_array( 'noindex', $robots_meta ) ) {
// If 'noindex' is found, prevent the hreflang tags from being output
$hreflang = '';
}
}
return $hreflang;
} );
I hope the above code helps you understand the process. However, I’d like to inform you that providing custom coding support is beyond the scope of our support. The code solution above is for demonstration purposes and may assist in solving the issue. If you require further coding assistance, you may need to hire a professional developer experienced in customizing WPML. You can find one here: https://wpml.org/contractors/.
I hope you can understand. Feel free to let me know if you have any other questions or need clarification. I'll be happy to help.