Multisite Language Switcher Simple, powerful and easy to use

Functions, classes & methods

In some cases it can be useful to have the possibility to use the functions and methods of the Multisite Language Switcher in a direct way.

Before you proceed: Backup your files and database prior to trying any of these examples here, better safe than sorry.

If you just look for further examples of how to integrate the plugin or interact with its functionality, then head over to this page.


This function can be placed anywhere in your theme-files such as header.php, footer.php and sidebar.php. It will echo an output similar to the widget.

if ( function_exists ( 'the_msls' ) ) {

You can also use some parameters to format the output to suit your needs.

if ( function_exists ( 'the_msls' ) ) {
    $args = array(
        'before_item'   => '<li>',
        'after_item'    => '</li>',
        'before_output' => '<ul>',
        'after_output'  => '</ul>',
    the_msls( $args );

This would create the output formatted in an unordered list.


Use this function if a string is needed because your theme handles the output in a different way, for example.

$str = '';
if ( function_exists ( 'get_the_msls' ) ) {
    $str = get_the_msls();

get_the_msls accepts the same parameters as the_msls.


All these functions use an object type of MslsOutput. The magic method ‘__toString’ handles all needs when this object is printed. But you can use the ‘get’-method directly if you want to work - for example - with the returning array of links before it is converted:

$object  = new MslsOutput();
$display = 0;
$exists  = false;

foreach ( $object->get( $display, $exists ) as $link ) {
    echo $link;

The parameter $display is an integer which can contain any number from 0 to 4. There is a static method in the class MslsLink which is used in a similar way in the option-page of the plugin:

print_r( MslsLink::get_types() );

If you want to show links to existing translations only set the parameter $exists to true.

Fork me on GitHub