My problem is that I have used a plugin called polylang and now it doesnät work with another more importent plugin so I need to find a solution. I use WPML on other sites and that is not an option here so you know.

I allready have all posts and pages translated and I just want to use one menu in Swedish and one in English. No changes in permalinks what so ever.

I found a solution in this post How to change menu according to the language? but I can’t get it to work. Not sure that post is still active or the solution works with WP 3.6 so I ask again for any help.

This is the menu code from the halifax theme

from the header

<?php wp_nav_menu( array( 'container_id' => 'submenu', 'theme_location' => 'primary','menu_id'=>'web2feel' ,'menu_class'=>'sfmenu','fallback_cb'=> 'fallbackmenu' ) ); ?>

code from the functions.php

    register_nav_menus( array(
        'primary' => __( 'Primary Navigation', '' ),
    ) );

function fallbackmenu(){ ?>
            <div id="submenu">
                <ul><li> Go to Adminpanel > Appearance > Menus to create your menu. You should have WP 3.0+ version for custom menus to work.</li></ul>
            </div>

1 Answer
1

Solved it with add_meta_box in functions.php. Here is my code:

add_action( 'add_meta_boxes', 'my_custom_box' );

function my_custom_box(){

    if ( function_exists('add_meta_box') ) {

        add_meta_box( 'page_custom_menu','page-menu', 'page_custom_menu_box', 'page', 'side','high');
        add_meta_box('page_custom_menu','page-menu', 'page_custom_menu_box', 'post', 'side', 'high');

    }

}

function page_custom_menu_box(){

    global $post;



    if ( metadata_exists( 'post', $post->ID, 'page_menu' ) ) {

        $menu_id = get_post_meta( $post->ID, 'page_menu', true );

    } 



    $entries = get_terms( 'nav_menu', array( 'hide_empty' => false ) );

    echo '<select class="postform" id="page_menu" name="page_menu"> ';

    echo '<option value="">Select...</option>  ';

    foreach ($entries as $key => $entry){

        $id = $entry->term_id;

        $title = $entry->name;

        if ( $id == $menu_id ){

            $selected = "selected='selected'";  

        }else{

            $selected = "";     

        }

        echo"<option $selected value="". $id."">". $title."</option>";

    }

    echo '</select>';

}



add_action('save_post', 'save_postdata');

function save_postdata( $post_id ) {   

    global $post;

    if( !isset($_POST['page_menu']) )

        return;

    $data = $_POST['page_menu'];

    if(get_post_meta($post_id, 'page_menu') == "") { 

       add_post_meta($post_id, 'page_menu', $data, true);

    }elseif($data != get_post_meta($post_id, 'page_menu', true)) { 

        update_post_meta($post_id, 'page_menu', $data);     

    }elseif($data == "")  { 

       delete_post_meta($post_id, 'page_menu', get_post_meta($post_id, 'page_menu', true));

    }

}

In header.php:

    if( is_page() && get_post_meta( $post->ID, 'page_menu', true )!='' ){

    global $post;

    $menu_id = get_post_meta( $post->ID, 'page_menu', true );

    wp_nav_menu( array( 'container_id' => 'submenu', 'menu' => $menu_id ) );

}elseif( is_single() && get_post_meta( $post->ID, 'page_menu', true )!='' ){

    global $post;

    $menu_id = get_post_meta( $post->ID, 'page_menu', true );

    wp_nav_menu( array( 'container_id' => 'submenu', 'menu' => $menu_id ) );

}else{

    //default menu

    wp_nav_menu( array( 'container_id' => 'submenu', 'theme_location' => 'primary','menu_id'=>'web2feel' ,'menu_class'=>'sfmenu','fallback_cb'=> 'fallbackmenu' ) ); 

}

Leave a Reply

Your email address will not be published. Required fields are marked *