• Resolved ebarcena

    (@ebarcena)


    I’m trying to add the bilingual linker to a menu but I don’t know how to do it. I found this code that successfully adds list items to my menu via the functions.php file but I don’t know how to include the function for the bilingual linker:

    add_filter('wp_nav_menu_items','search_and_lang', 10, 2);
    function search_and_lang( $nav, $args ) {
        if( $args->theme_location == 'top-menu' )
            return $nav."
            <li class='menu-header-search'>
                <?php the_bilingual_link(); ?>
            </li>
            <li class='menu-header-search'>
                <form action='https://example.com/' id='searchform' method='get'><input type='text' name='s' id='s' placeholder='Search'></form>
            </li>";
    
        return $nav;
    }

    Any help will be appreciated. Thanks!

    https://www.ads-software.com/plugins/bilingual-linker/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Yannick Lefebvre

    (@jackdewey)

    What type of output are you currently getting in the page source when you are calling the the_bilingual_link function? Is there nothing coming out at all? Or is the output not formatted as expected?

    Thread Starter ebarcena

    (@ebarcena)

    No output at all. The list item comes out blank. Here is a screenshot while inspecting using firebug:

    https://www.dropbox.com/s/4z20kys8gs0prdl/Screenshot%202014-08-13%2018.17.31.png

    This is the code I’m trying to use:

    /*-----------------------------------------------------------------------------------*/
    /* Adds menu items to top navigation */
    /*-----------------------------------------------------------------------------------*/
    add_filter('wp_nav_menu_items','search_and_lang', 10, 2);
    function search_and_lang( $nav, $args ) {
        if( $args->theme_location == 'top-menu' )
            return $nav."
            <li class='social'><a href='https://www.facebook.com/diosesoficial' class='facebook' title='Facebook'></a></li>
            <li class='social'><a href='https://www.twitter.com/diosesoficial' class='twitter' title='Twitter'></a></li>
            <li class='social'><a href='https://www.youtube.com/diosesoficial' class='youtube' title='YouTube'></a></li>
            <li class='social'><a href='https://instagram.com/diosesoficial' class='instagram' title='Instagram'></a></li>
            <li class='social'><a href='https://plus.google.com/104359249738911754009/' class='googleplus' title='Google+'></a></li>
            <li class=''><?php the_bilingual_link(); ?></li>
            ";
    
        return $nav;
    }

    Thanks!

    Plugin Author Yannick Lefebvre

    (@jackdewey)

    This may sound like an obvious questions, but did you go in the settings section for Bilingual Linker and set your list of languages, along with the default translation URL for each language?

    Thread Starter ebarcena

    (@ebarcena)

    Yes I did. In fact, I’m using it successfully on the sidebar but I need it placed in that top navigation.

    Thanks for your help.

    Plugin Author Yannick Lefebvre

    (@jackdewey)

    Sorry for the lack of response. I will need to investigate further but am busy all week-end with WordCamp Montreal. I will likely be able to look into this Monday evening next week.

    I took a quick look at the code just now and do not understand why it’s not outputting anything, especially if you tell me that it works in other places.

    Thread Starter ebarcena

    (@ebarcena)

    Hey thanks Yannick!

    No rush, I can wait. The site is still a being worked on, in the meanwhile the sidebar language switcher will suffice.

    Thanks again.

    Plugin Author Yannick Lefebvre

    (@jackdewey)

    The problem is that you placed the PHP function call in the middle of a string. Also, by default, the function to display the bilingual link echos text immediately. You need to specify that you do not want it to echo in the parameters. Please find the corrected code below:

    /*-----------------------------------------------------------------------------------*/
    /* Adds menu items to top navigation */
    /*-----------------------------------------------------------------------------------*/
    add_filter('wp_nav_menu_items','search_and_lang', 10, 2);
    function search_and_lang( $nav, $args ) {
        if( $args->theme_location == 'top-menu' )
            return $nav."
            <li class='social'><a href='https://www.facebook.com/diosesoficial' class='facebook' title='Facebook'></a></li>
            <li class='social'><a href='https://www.twitter.com/diosesoficial' class='twitter' title='Twitter'></a></li>
            <li class='social'><a href='https://www.youtube.com/diosesoficial' class='youtube' title='YouTube'></a></li>
            <li class='social'><a href='https://instagram.com/diosesoficial' class='instagram' title='Instagram'></a></li>
            <li class='social'><a href='https://plus.google.com/104359249738911754009/' class='googleplus' title='Google+'></a></li>
            <li class=''>" . the_bilingual_link( '', '', '', '', '', '', false ) . "</li>
            ";
    
        return $nav;
    }

    Please let me know if this resolves the issue on your development site and mark the issue as resolved if it does. Also consider rating Bilingual Linker! ??

    Thread Starter ebarcena

    (@ebarcena)

    Hey Yannick thanks a lot.

    It’s almost there. The switcher finally displays and it works correctly, but the problem now is that it also prints out the language’s home URL twice, before and after the language link.

    Check it out:

    https://www.dropbox.com/s/buik72h9lhdj3ea/Screenshot%202014-08-21%2018.21.12.png

    Plugin Author Yannick Lefebvre

    (@jackdewey)

    Can you post a screenshot of the Bilingual Linker configuration panel? This did not happen on my local test.

    Thread Starter ebarcena

    (@ebarcena)

    Plugin Author Yannick Lefebvre

    (@jackdewey)

    Ah, I see. Make the Before Translation Link and After Translation Link fields empty. These fields are meant to let you output text or html code before and after the translation links. You should be all set after that.

    Thread Starter ebarcena

    (@ebarcena)

    Yes! It’s working perfectly now. Thank you very much. As an independent band with pretty much no budget, you sir and your plugin have made it possible for us to have a dynamically bilingual website.

    Thanks a lot.

    I will mark as resolved and will rate right now!

    Thread Starter ebarcena

    (@ebarcena)

    Resolved.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How can add the Bilingual Linker to a menu?’ is closed to new replies.