WordPress.org

Forums

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

  1. lucaslem
    Member
    Posted 1 year 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. Dennis Ploetner
    Member
    Plugin Author

    Posted 1 year 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 1 year 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 1 year 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 1 year 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. Dennis Ploetner
    Member
    Plugin Author

    Posted 1 year 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 1 year 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 1 year 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. Dennis Ploetner
    Member
    Plugin Author

    Posted 1 year 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 1 year 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!

  11. Jejedefrancia
    Member
    Posted 9 months ago #

    Hi guys,

    First, thanks very for this plug-in love it !!!

    I spent some time on my gf's website lately. We'd like to put the output menu next to the Facebook/Tumblr pics on the top rig (the black area) but we can't. I understand how the plug-in works but i don't know how to put the right code. Some help please :)

    Thx a lot

  12. Dennis Ploetner
    Member
    Plugin Author

    Posted 9 months ago #

    Hi,

    let's move this conversation to another thread. Please let me know in this new thread what theme you use and maybe the URL too, ok?

    Cheers,
    Dennis.

  13. Jejedefrancia
    Member
    Posted 9 months ago #

    Hey,

    this is the new thread : link

    Thx a lot Dennis

  14. raphaelpinel1
    Member
    Posted 8 months ago #

    Hello!
    Thank you. Victory! It works on my site
    http://raphaelpinel.com/now/
    I used the first method
    I am new to wordpress, so it is a miracle that it is working for me.
    Here is what I dit:
    I copied the code here:
    https://github.com/lloc/Multisite-Language-Switcher/wiki/Generate-the-output#manipulate-the-navigation-menu
    I pasted it in functions.php in my theme-child folder
    uploaded per FTP
    That's it!
    Wonderful!
    I am using the Speaker theme from theme forest wpwolf

    thank you so much for the great plugin and great support.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Multisite Language Switcher
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic