Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/1ed84ce58507e1f50b88f06edad2f098 to your computer and use it in GitHub Desktop.
Save dwanjuki/1ed84ce58507e1f50b88f06edad2f098 to your computer and use it in GitHub Desktop.
Add member's name to Top Bar Nav menu location (OceanWP theme)
<?php
/**
* Add "Welcome, User Display Name" to the OceanWP Top Bar menu location
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_oceanwp_add_welcome_user_nav_menu_item( $items, $args ) {
if ( 'topbar_menu' === $args->theme_location && is_user_logged_in() ) {
$user = wp_get_current_user();
$items = '<li><a href="#">Welcome, ' . $user->display_name . '</a></li>' . $items;
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_oceanwp_add_welcome_user_nav_menu_item', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment