I’m making an attempt so as to add an avatar picture to the highest nav menu. I’m presently utilizing this operate, which takes a customized hyperlink and replaces it with the presently logged in consumer’s title. That a part of the operate works wonderful.
My makes an attempt to switch the operate have not gotten me throughout the end line but. Sure, there’s a query on right here that’s type of similiar, Inserting PHP earlier than a menu aspect, whereas utilizing the inbuilt menu operate wp_nav_menu(), and I’ve learn it, however there is not actually sufficient clarification on it to assist me with my setup.
Here is the modified operate from my features.php file:
operate my_custom_menu_item($gadgets) {
$remove_childs_of = array();
if($item->title == "##currentuser##") {
if(is_user_logged_in()) {
$consumer=wp_get_current_user();
$dimension = 'thumbnail';
$imgURL='';
if (function_exists('get_wpupa_url'))
$imgURL = get_wpupa_url($user->id, ['size' => $size]);
echo "<img class='avatar-menu' src='" . $imgURL ."'>";
$title=$user->display_name; // or user_login , user_firstname, user_lastname
$gadgets[$index]->title = $title;
}
else {
array_push($remove_childs_of, $item->ID);
unset($gadgets[$index]);
}
}
if(!empty($remove_childs_of) && in_array($item->menu_item_parent, $remove_childs_of)) {
array_push($remove_childs_of, $item->ID);
unset($gadgets[$index]);
}
return $gadgets;
}
?>
Whereas this does technically work, since I am not really inserting the picture into the array of the operate $gadgets[$index]
, that is maybe the place I am going improper?
Thanks for any solutions you nice of us may need. 🙂