Tag Info

Hot answers tagged

2

This is relatively easily done using the walker_nav_menu_start_el filter (without all that PHP tag spam): function nav_replace_wpse_189788($item_output, $item) { // var_dump($item_output, $item); if ('Profile' == $item->title) { global $my_profile; // no idea what this does? if (is_user_logged_in()) { return '<div class="img" ...


1

You can try this out : <?php global $my_profile; ?> <?php if (is_user_logged_in()){ $avatar = '<div class="img" data-key="profile">'.get_avatar( get_current_user_id(), 64 ).'</div>'; }else{ $avatar = ''; } ?> And your menu code should be like this $defaults = array( 'theme_location' => 'location of menu in ...


1

Add to your functions file and use wp_nav_menu_items add_filter('wp_nav_menu_items','wpsites_add_avatar_to_nav', 10, 2); function wpsites_add_avatar_to_nav( $items, $args ) { if( $args->theme_location == 'primary' ) return $items; $dude = get_avatar( get_current_user_id(), 48 ); if (is_user_logged_in()) : echo'<li ...


1

Found the answer. It might not be the best way to do it but it is working for now. I was looking on using a filter when the solution seems to be using a custom walker. class edited_menu_walker extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { global $wp_query; $indent = ( $depth ) ? str_repeat( "\t", ...


1

I believe the filter you want is wp_get_nav_menus: function wp_get_nav_menus( $args = array() ) { $defaults = array( 'hide_empty' => false, 'orderby' => 'name' ); $args = wp_parse_args( $args, $defaults ); /** * Filter the navigation menu objects being returned. * * @since 3.0.0 * * @see get_terms() * * ...


1

Presonally, I would use some CSS workaround. In menu administration you can add CSS class to menu item (if the field is not displayed, you can find it in Screen Options), for example "profile-link". And than you can add something like this to your template HEAD section: <?php $avatar = get_avatar_url( get_current_user_id(), array('size' => 64) ); // ...



Only top voted, non community-wiki answers of a minimum length are eligible