What I have:

I have a log-in/log-out link in a standard WordPress navigation menu. So far, I’ve conditionally filtered the URL to either the necessary log-on or log-out urls.

What I need:

I also need to conditionally change the textual value of a link (menu item) in the navigation menu.

My code:

add_filter( 'nav_menu_link_attributes', 'menu_override_b', 10, 3 );
function menu_override_b( $atts, $item, $args ) {
    if ( is_user_logged_in() ) {
        $url = wp_logout_url();
        $newlink = str_replace("http://--loginout--", $url, $atts[href]);
        $atts[href] = $newlink; 
        //None of the following work...
        /*
        $title ="Logout";
        $atts[title] = $title;  
        $atts[post_excerpt] = $title;
        $atts[description] = $title;
        $atts[attr_title] = $title;
        $atts[post_title] = $title;
        $atts[post_content] = $title;
        */
    }
    else{
        $url = "/somewhere/else";
        $newlink = str_replace("http://--loginout--", $url, $atts[href]);
        $atts[href] = $newlink; 
        //None of the following work...
        /*
        $title ="Login";
        $atts[title] = $title;  
        $atts[post_excerpt] = $title;
        $atts[description] = $title;
        $atts[attr_title] = $title;
        $atts[post_title] = $title;
        $atts[post_content] = $title;
        */
    }   
    return $atts;
}

List of WordPress menu item attributes

Read more here: Change/filter text of link of navigation menu


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: