Añadimos al functions.php del tema hijo el siguiente código:
//Añadir links alternate a las páginas que no son single function relateEs(){ global $wp_query; global $sitepress; $url = add_query_arg( NULL, NULL ); echo "<link rel='alternate' href='https://eli1957.com$url' hreflang='x-default'/>\n"; if(get_locale() == 'es_ES'){ $sitepress->switch_lang('en'); if( is_single() ){ $wpml_permalink = get_permalink(icl_object_id($wp_query->post->ID,'page',false)); echo "<link rel='alternate' href='$wpml_permalink' hreflang='en'/>\n"; }elseif( is_archive() ) { $page_id = get_queried_object_id(); $wpml_permalink = get_category_link( icl_object_id( $page_id , 'category' , true , 'en' ) ); echo "<link rel='alternate' href='$wpml_permalink' hreflang='en'/>\n"; }else{ echo "<link rel='alternate' href='https://eli1957.com/blog/en' hreflang='en'/>\n"; } $sitepress->switch_lang('es'); }else{ $sitepress->switch_lang('es'); if( is_single() ){ $wpml_permalink = get_permalink(icl_object_id($wp_query->post->ID,'page',false)); echo "<link rel='alternate' href='$wpml_permalink' hreflang='es'/>\n"; }elseif( is_archive() ){ $page_id = get_queried_object_id(); $wpml_permalink = get_category_link( icl_object_id( $page_id , 'category' , true , 'es' ) ); echo "<link rel='alternate' href='$wpml_permalink' hreflang='es'/>\n"; }else{ echo "<link rel='alternate' href='https://eli1957.com/blog/' hreflang='es'/>\n"; } $sitepress->switch_lang('en'); } } add_filter( 'wp_head', 'relateEs', 9999 );