WordPress.org

Forums

Multisite Language Switcher
[resolved] SEO links in header (12 posts)

  1. henkmensinga
    Member
    Posted 2 years ago #

    I would like to add seo friendly stuff to the header like:


    <link rel="alternate" hreflang="es" href="http://www.example.com/" />
    <link rel="alternate" hreflang="en" href="http://en.example.com/" />

    I can't find a way to have an extra output that can generate this. If I would use a filter, my standard switcher would also change.

    Any idea how to do this?

    http://wordpress.org/extend/plugins/multisite-language-switcher/

  2. Dennis Ploetner
    Member
    Plugin Author

    Posted 2 years ago #

  3. henkmensinga
    Member
    Posted 2 years ago #

    Not quite, but it's a start.

    You missed a , in the printf.

    Languagecode are full like en_GB, but i just need en (which i can strip in the code I guess)

    I need full urls to the blog and translations including current language.
    So different for each blog item or page.

    Thanks so far!

  4. Dennis Ploetner
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, you can use substr( $blog->get_language(), 0, 2 ) in this case.

    Please read on here: https://github.com/lloc/Multisite-Language-Switcher/wiki/Change-the-output

  5. henkmensinga
    Member
    Posted 2 years ago #

    Got that.

    Any idea about the individual urls?

  6. henkmensinga
    Member
    Posted 2 years ago #

    Ok, got this to work, thanks for your help!

    function my_print_something() {
        foreach ( MslsBlogCollection::instance()->get() as $blog ) {
    	$lang = $blog->get_language();
    	$mydata = MslsOptions::create();
    	switch_to_blog( $blog->userblog_id );
            printf(
                '<link rel="alternate" hreflang="%1$s" href="%2$s" />',
                substr( $blog->get_language(), 0, 2 ),
    			$mydata->get_permalink($lang)
            );
    		restore_current_blog();
        }
    }
    add_action( 'wp_head', 'my_print_something' );
  7. henkmensinga
    Member
    Posted 2 years ago #

    Resolved

  8. Dennis Ploetner
    Member
    Plugin Author

    Posted 2 years ago #

    OK, excellent. I added some code here.

    Could tell something about the alternative links?

  9. henkmensinga
    Member
    Posted 2 years ago #

    Thanks for cleaning up 😃

    The hreflang alternate tags are for SEO purposes. Making Google and others understand the structure of the multilingual content.

    http://support.google.com/webmasters/bin/answer.py?hl=en&answer=2620865

  10. Dennis Ploetner
    Member
    Plugin Author

    Posted 2 years ago #

    Very good! Thanks for pointing that out.

  11. Lorangeo
    Member
    Posted 1 year ago #

    Please, would you like to consider adding this feature into the plugin?

    hreflang attribute is of great value in this kind of setup.

    Vielen Dank für das Plugin!

  12. Dennis Ploetner
    Member
    Plugin Author

    Posted 1 year ago #

    Gern geschehen!

    Yes, this feature will probably added to the plugin in the near future: https://github.com/lloc/Multisite-Language-Switcher/issues/45

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic