2016-07-27 39 views
0

我使用woocommerce,並使用woocommerce插件添加一個菜單我的帳戶但我想顯示菜單登錄和註銷,而不是我添加到菜單中的我的帳戶。我也將腳本添加到functions.php結果是相同的。如何替換我的賬戶並添加登錄/註銷鏈接到Woocommerce的菜單?

add_filter('wp_nav_menu_items', 'add_loginout_link', 10, 2); 

function add_loginout_link($items, $args) { 

    if (is_user_logged_in() && $args->theme_location == 'primary_navigation') { 

     //echo "hello friend how are"; 

     $items .= '<li><a href="'. wp_logout_url(get_permalink(woocommerce_get_page_id('myaccount'))) .'">Log Out</a></li>'; 

    } 

    elseif (!is_user_logged_in() && $args->theme_location == 'primary_navigation') { 

     $items .= '<li><a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">Log In</a></li>'; 

    } 

    return $items; 

} 

當我使用jupitor主題,當我看到我的帳戶菜單主題的位置,我得到

主導航 我有一個疑問,就是我得先加我的帳戶菜單然後我添加登錄和註銷菜單。

回答

2

您的上述代碼將添加登錄/註銷鏈接到菜單。您不必添加我的賬戶菜單。

請檢查您的theme_location。如果主題位置正確,則登錄/註銷鏈接將添加到菜單。

對於檢查theme_location,您必須在您的主題的functions.php文件中搜索register_nav_menus。如果你在functions.php文件中找到它,你可以在register_nav_menus代碼中看到theme_location。

+0

是的,我給了錯誤的主題位置我的主題位置是主菜單 –

相關問題