Skip to:
Content
Pages
Categories
Search
Top
Bottom

Profile in menu – php


  • Don46
    Participant

    @don46

    WP 4.6 BBpress plugin 2.5.10
    I am using some of the super BBpress code suggestions at https://codex.bbpress.org/layout-and-functionality-examples-you-can-use/ and most work just fine ‘out of the box’ but I am not sure what I should be putting in place of ‘ my_nav_menu_profile_link’ in this one. If I put in the code as is….

    // Filter wp_nav_menu() to add profile link
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link' );
    function my_nav_menu_profile_link($menu) {
        if (!is_user_logged_in())
            return $menu;
        else
            $current_user = wp_get_current_user();
            $user=$current_user->user_nicename ;
            $profilelink = '<li><a href="/forums/users/' . $user . '/edit">Edit Profile</a></li>';
            $menu = $menu . $profilelink;
            return $menu;
      
    }

    I get this when trying the menu link……
    Object not found!
    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
    If you think this is a server error, please contact the webmaster.
    Error 404
    localhost
    Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.24

    If I replace the ‘ my_nav_menu_profile_link’ with the actual link like this…..

    /* Profile link in menu....................*/
    // Filter wp_nav_menu() to add profile link
    add_filter( 'wp_nav_menu_items', 'http://localhost/wordpress/wp-admin/profile.php' );
    function http://localhost/wordpress/wp-admin/profile.php($menu) {
        if (!is_user_logged_in())
            return $menu;
        else
            $current_user = wp_get_current_user();
            $user=$current_user->user_nicename ;
            $profilelink = '<li><a href="/forums/users/' . $user . '/edit">Edit Profile</a></li>';
            $menu = $menu . $profilelink;
            return $menu;
      
    }

    I get this as soon as I go to the site…

    Parse error: syntax error, unexpected ‘:’, expecting ‘(‘ in C:\xampp\htdocs\wordpress\wp-content\themes\twentytenchild\functions.php on line 49
    What should I be entering and when I move to a live site will it need to be further changed?

  • You must be logged in to reply to this topic.
Skip to toolbar