WordPress.org

Ready to get started?Download WordPress

Forums

help me to create language switching button/link (1 post)

  1. Ronald
    Member
    Posted 1 year ago #

    I'm building multi-language blog and I still need the activate button(or)link which can let the users switch any language.

    I've coded as below and when I click(or)switch my-language it's still find, but when I reload to the new page my-language is disappear and it automatically changes to the default language.
    can someone guide me to the right way, I think sth wrong with my code.

    ----------------------------------------------------------------------

    // * header.php  * //
    <a href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>/?lang=mylanguage">French</a>
    <a href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>/?lang=eng">English</a>

    ----------------------------------------------------------------------

    // * function.php  *//
    <?php
    session_start();
    
    $_SESSION['language'] = $_GET['lang'];
    
    if ( $_SESSION['language'] == 'mylanguage' ) {
    
    require (TEMPLATEPATH .'/languages/my-language.php');
    
    }
    else {
    
    require (TEMPLATEPATH .'/languages/english.php');  // default language
    
    }
    ?>

    -----------------------------------------------------------------------

Topic Closed

This topic has been closed to new replies.

About this Topic