[Support request] how to add WPML language switcher to Nav

Home Forums Support [Support request] how to add WPML language switcher to Nav

Home Forums Support how to add WPML language switcher to Nav

  • This topic has 7 replies, 4 voices, and was last updated 3 years ago by David.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #867859
    Jochen

    Hi,

    I am working on a multilanguage page using WPML and Elementor. Although I can have WPML add the switcher as first or last Menu-Element this is not the look that I want and does not work if set to DropDown.

    I think it might be a good idea to add a widget area to the Nav area and add the swithcer there with some optical adjustments. Is there a howto to help with this?

    Thx
    Jochen

    GP Premium 1.7.8
    #867987
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You could register a new widget area:

    add_action( 'widgets_init', function() {
        register_sidebar( array(
            'name'          => 'Your Widget Area Name',
            'id'            => 'your-widget-area-id',
            'before_widget' => '<div>',
            'after_widget'  => '</div>',
            'before_title'  => '<h2>',
            'after_title'   => '</h2>',
        ) );
    } );

    Then you can:

    1. Create a new Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
    2. Set the hook to inside_navigation
    3. Add the widget area to the content:

    <div class="wpml-switcher">
        <?php dynamic_sidebar( 'your-widget-area-id' ); ?>
    </div>

    4. Check the Execute PHP checkbox
    5. Set your Display Rules

    Now you can add some CSS like this:

    .wpml-switcher {
        float: right;
    }
    #1194587
    Klaus

    Hello, I have two questions: is this still the code I can use for this task and second: how do I get or set the “your-widget-area-id”? Thank you.

    #1194595
    David
    Staff
    Customer Support

    Hi there,

    yes you can use this code for adding the WPML widget to the navigation.

    In the first block of code, you set your own name and area-id:

    'name'          => 'Your Widget Area Name',
    'id'            => 'your-widget-area-id',
    #1194596
    Klaus

    Hello again, it seems that I can have anything as “ID” here, right? My problem is, that it does not want to float right (but it stays in the navigation left), as I have “navigation as a header” floating right also.

    #1194600
    David
    Staff
    Customer Support

    That is correct you can put anything that in the ID as long as it is not being used by another widget area 🙂
    I would do this for example:

    db-navigation-switcher-widget

    the db is my initials so will reduce the chance that the ID has already been used.

    If you want to raise a new topic where you can privately share a link to your site i’ll take a look

    #1194750
    Klaus

    Hello David, thanks for explaining. Here is my new post:

    https://generatepress.com/forums/topic/wpml-language-switcher-doesn-go-to-the-right/

    #1194770
    David
    Staff
    Customer Support

    Thank you – i have replied.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.