mardi 5 avril 2016

How to add hreflang=''x-default'' in WPML 3.3.6 plugin?

WPML is an excellent plugin for managing multilingual sites as it allows to edit a lot of relevant info related to translated content. However, although this plugin adds hreflang tags, theres is a lack of support for hreflang="x-default" anotation.

So I would like to know how to add this x-default tag to WPML sites, and make it to point to my desired language version of an URL.

There are some examples of code in WPML forums, but they are intended for older versions of this plugin. All of them point to edit the head_langs function, that currently consists on the following code:

function head_langs()
    {
        $languages = $this->get_ls_languages( array( 'skip_missing' => true ) );
        // 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 = 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 ) {
            foreach ( $languages as $code => $lang ) {
                $alternate_hreflang = apply_filters( 'wpml_alternate_hreflang', $lang[ 'url' ], $code );
                printf( '<link rel="alternate" hreflang="%s" href="%s" />' . PHP_EOL,
                        $this->get_language_tag( $code ),
                        str_replace( '&amp;', '&', $alternate_hreflang ) );
            }
        }
    }

Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire