• I want to make my wordpress menus to be localize but im stuck on to how can i make it. I tried the wp_nav_menu() parameters ‘link_before’ and ‘link_after’ and insert but cannot make it done. Please shed some light. thanks

    <div id=”navbar” class=”navbar-collapse collapse”>

    <?php

    $args = array(
    ‘menu’ => ‘header-menu’,
    ‘menu_class’ => ‘nav navbar-nav navbar-right’,
    ‘container’ => ‘false’,
    ‘link_before’ => ‘<?php _e(\”,
    ‘link_after’ => ‘ \’, \’text_domain\’); ?>’
    );

    wp_nav_menu( $args );

    ?>

    </div><!–/.navbar-collapse –>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You cannot localize variables, they need to be fixed strings. Variables can only be incorporated using printf() format where placeholders like %s occur where a variable’s value would be placed. Of course the variable itself is not translated, just the string around it.

    The nav menu normally does not have any fixed strings except maybe “menu”. Everything is based on user input, user input cannot be localized.
    https://developer.wordpress.org/themes/functionality/localization/

    Thread Starter sonny12

    (@sonny12)

    ok. Any other option to do the trick? Because I need to have a navigation that has two language one for english (default) and second option for (arabic). I saw some sites that their navigation will translate to different language but I have no idea how they do it.

    Moderator bcworkz

    (@bcworkz)

    You’d need different menus defined for each location, one for each language. Each menu item is a special post type: nav_menu_item. There is a special taxonomy to determine what menu each post belongs to: nav_menu. All posts in a menu are assigned the same term. The term ID of the menu is assigned to a menu location in the theme mod settings in the options table. The option key is “theme_mods_{$theme_name}”.

    To swap menus, determine the term ID from the terms table based on the menu name. Confirm the term is in the right taxonomy with the term_taxonomy table. Set the ID for the menu location in the theme mods option.

    Then when wp_nav_menu() is called for a particular location, WP gets the nav_menu posts that have the menu name term assigned which corresponds to the ID saved in theme mods. The menu order and parent values are used to construct the menu.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to make wordpress navigation menu localize’ is closed to new replies.