WordPress add to menu on the fly

add_filter( ‘wp_nav_menu_items’, ‘your_custom_menu_item’, 10, 2 );
function your_custom_menu_item ( $items, $args ) {
//if (is_front_page()) { $items .= ‘<li>Show whatever</li>’; }else{ $items .= ‘<li>Show something else</li>’; }

if ( is_page( array( ‘meet-the-group’, ‘contact-us’ ) ) || is_front_page()) {
// either in about us, or contact, or management page is in view
//$items .= ‘<li>Show whatever</li>’;
$left = ‘<li id=”menu-item-4016″ class=”red menu-item menu-item-type-post_type menu-item-object-page menu-item-home menu-item-4016″><a class=”no-border” href=”https://agingcareassurance.com/one-pager/”>’;
$middle = ‘<img src=”https://agingcareassurance.com/wp-content/uploads/2021/09/one-page.small_.png” alt=”” />’;
$right = ‘</a></li>’;
$items .= $left . $middle . $right;

} else {
// none of the page about us, contact or management is in view
{
$left = ‘<li id=”menu-item-4016″ class=”red menu-item menu-item-type-post_type menu-item-object-page menu-item-home menu-item-4016″><a class=”no-border” href=”https://agingcareassurance.com/”>’;
$middle = ‘<img src=”https://agingcareassurance.com/wp-content/uploads/2021/09/multi.small_.png” alt=”” />’;
$right = ‘</a></li>’;
$items .= $left . $middle . $right;
}
};

return $items;

}