WordPress.org

Ready to get started?Download WordPress

Forums

Multisite Language Switcher
[resolved] Inserting Multisite Language Switcher link inside Genesis primary navigation (10 posts)

  1. lucaslem
    Member
    Posted 10 months ago #

    Hello,

    I would like to have the language switcher appear within my main navigation (custom child theme based on the Genesis framework) rather than a separate block level element/widget.

    I am a front-end guy relatively new to PHP, but I have so far manage to set up custom post types and custom taxonomy so I can catch on quickly with clear instructions and code exmaples.

    Thanks to anyone who can point me in the right direction.

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

  2. realloc
    Member
    Plugin Author

    Posted 10 months ago #

    Hello,

    there are at least 2 ways how to do this (a simple one and a little bit more - but not so scary - complex one).

    I believe that the ID of your menu is 'primary-nav' (I use the Genesis Framework too). So in the first example you have just to modify the ID:

    https://github.com/lloc/Multisite-Language-Switcher/wiki/Generate-the-output#manipulate-the-navigation-menu

    The second one has some lines of code more than the other one. I made this plugin for my blog but I think it is a good example for you:

    https://github.com/lloc/MslsMenu

    Cheers,
    Dennis.

  3. lucaslem
    Member
    Posted 10 months ago #

    Hi Dennis,

    Thanks so much for your instructions. I am trying to achieve my goal with the second option (the plugin) but I am having some trouble.

    It seems that *some* of code is indeed making from the MslsMenu plugin, however it is not being added to the correct location and no new classes are added to the actual link for styling. Sadly I am still working locally so I don't have any links to show any source code, but here are a couple screenshots:
    http://cl.ly/image/2r2h1L3A3G1Q
    http://cl.ly/image/3U3O0w1C3H1L

    The only modification I made to your plugin code is changing primary-nav to menu-primary-navigation (the id of the menu to which I would like to add the link)

    Any additional guidance would be great.

  4. lucaslem
    Member
    Posted 10 months ago #

    I should be clear (though it shows in the source code screen shot) that my primary menu is located in the header-right widget area... My guess is this is creating the issue?

  5. lucaslem
    Member
    Posted 10 months ago #

    I realize your code targets the navigation by theme location (Primary). I wonder then, is there a way to target the nav in the header-right widget area follwoing the same logic, or possibly by ID?

  6. realloc
    Member
    Plugin Author

    Posted 10 months ago #

    The term "ID" is probably a little bit confusing. There is - I'm quite sure - a call to register_nav_menu which regsiters a menu with a specific handle. This is what I use to manipulate the right menu.

  7. lucaslem
    Member
    Posted 10 months ago #

    What I mean is perhaps targeting by menu name or ul ID as described here: http://codex.wordpress.org/Function_Reference/wp_nav_menu

  8. lucaslem
    Member
    Posted 10 months ago #

    Using your first option for example, if I change the code like this to target by menu name:

    function my_custom_menu_item( $items, $args ) {
        if ( class_exists( 'MslsOutput' ) && 'my menu name' == $args->menu ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
            }
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );

    or like this to target menu ul id:

    function my_custom_menu_item( $items, $args ) {
        if ( class_exists( 'MslsOutput' ) && 'menu-idname' == $args->menu_id ) {
            $obj = new MslsOutput;
            $arr = $obj->get( 2 );
            if ( !empty( $arr ) ) {
                $items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
            }
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );

    Shouldn't it also work?

  9. realloc
    Member
    Plugin Author

    Posted 10 months ago #

    wp_nav_menu_items is a filter-hook. You should check what is in $items and $args. Why not just check the name of the handle?

    Read on here: http://wordpress.stackexchange.com/questions/2143/customizing-only-a-specific-menu-using-the-wp-nav-menu-items-hook

  10. lucaslem
    Member
    Posted 10 months ago #

    THANK-YOU!!!! This worked perfectly! Backend is VERY new to me I can't thank-you enough for your patience and support in this. Your plugin is really superb for those of us living in bilingual areas and who do not want to use plugins like WPML.
    Cheers!

Reply

You must log in to post.

About this Plugin

About this Topic