Skip to content

Instantly share code, notes, and snippets.

@giventofly
Created May 12, 2021 20:10
Show Gist options
  • Save giventofly/a7864f66d2c76c1558fe51501a04f449 to your computer and use it in GitHub Desktop.
Save giventofly/a7864f66d2c76c1558fe51501a04f449 to your computer and use it in GitHub Desktop.
wordpress add items to menu programatically
<?php
//add items to menu
add_filter( 'wp_nav_menu_items', 'add_extra_item_to_nav_menu', 10, 2 );
function add_extra_item_to_nav_menu( $items, $args ) {
if (is_user_logged_in() && $args->menu == 1357) {
$items .= '<li><a href="'. get_permalink( get_option('woocommerce_myaccount_page_id') ) .'">My Account</a></li>';
}
elseif (!is_user_logged_in() && $args->menu == 1357) {
$items .= '<li><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Sign in / Register</a></li>';
}
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment