Skip to content

Instantly share code, notes, and snippets.

@digitalchild
Created October 24, 2014 11:25
Show Gist options
  • Select an option

  • Save digitalchild/37cf1437bb6aed14c6e9 to your computer and use it in GitHub Desktop.

Select an option

Save digitalchild/37cf1437bb6aed14c6e9 to your computer and use it in GitHub Desktop.
Hijack Wordpress menu to insert shop link
<?php
// Hijack menu to insert vendor shop link.
add_filter('wp_nav_menu_items', 'vendor_shop_link', 10, 2);
function vendor_shop_link($items, $args) {
$wcv_settings = get_option('wc_prd_vendor_options');
$wcv_perm = $wcv_settings['vendor_shop_permalink'];
// This assumes that this menu is only visible to vendors
// Change the menu reference on the next line
if( is_user_logged_in() && ( $args->menu->slug == 'insert-your-menu-name-here' ) ) {
$shop = get_userdata( get_current_user_id() );
$shop_link = site_url($wcv_perm.'/' .$shop->pv_shop_slug );
$sp = '<li><a title="View Shop" href="'.$shop_link .'">View Shop</a></li>';
$newitems = $sp . $items;// enqueue regular menu item
return $newitems;
}
// for menus other than 'header-menu', get regular menu
return $items;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment