Created
April 6, 2016 16:02
-
-
Save andreasciamanna/393cfce371ba7b1d6b66f4ac904bf748 to your computer and use it in GitHub Desktop.
\WPML_SEO_HeadLangs::head_langs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function head_langs() { | |
$languages = $this->sitepress->get_ls_languages( array( 'skip_missing' => true ) ); | |
$languages = apply_filters( 'wpml_head_langs', $languages ); | |
// If there are translations and is not paged content... | |
//Renders head alternate links only on certain conditions | |
$the_post = get_post(); | |
$the_id = $the_post ? $the_post->ID : false; | |
$is_valid = is_array( $languages ) && count( $languages ) > 1 && ! is_paged() && ( ( ( is_single() || is_page() ) && $the_id && get_post_status( $the_id ) === 'publish' ) || ( is_home() || is_front_page() || is_archive() ) ); | |
if ( $is_valid ) { | |
$hreflang_items = array(); | |
foreach ( $languages as $code => $lang ) { | |
$alternate_hreflang = apply_filters( 'wpml_alternate_hreflang', $lang['url'], $code ); | |
$hreflang_items[ $this->sitepress->get_language_tag( $code ) ] = str_replace( '&', '&', $alternate_hreflang ); | |
} | |
$hreflang_items = apply_filters( 'wpml_hreflangs', $hreflang_items ); | |
$hreflang = ''; | |
if ( is_array( $hreflang_items ) ) { | |
foreach ( $hreflang_items as $hreflang_code => $hreflang_url ) { | |
$hreflang .= '<link rel="alternate" hreflang="' . esc_attr( $hreflang_code ) . '" href="' . esc_url( $hreflang_url ) . '" />' . PHP_EOL; | |
} | |
} | |
echo apply_filters( 'wpml_hreflangs_html', $hreflang ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment