Moodle extend_navigation_user with custom link

Moodle extend_navigation_user with custom link

by Christos Savva -
Number of replies: 1

Hello Moodlers

I am trying to extend the Moodle user menu to add a link (where the red arrow is) using a local plugin.

Moodle User Menu

I have the following code

function local_myplugin_extend_navigation_user($parentnode, $user, $context, $course, $coursecontext) {

    $url = new moodle_url('/local/myplugin/preferences.php');
    $subsnode = navigation_node::create(get_string('preferenceslink', 'local_myplugin'), $url,
    navigation_node::TYPE_SYSTEM, null, 'test', new pix_icon('i/settings', ''));
    
    $parentnode->add_node($subsnode);
}

For some reason this does not do the trick. I even tried to var_dump($parentnote) I see that my custom link appears there but it does not show on the menu when I open the actual page.

I read the Moodle docs but I can't figure out whats going on.

Anyone managed to do this?


Average of ratings: -
In reply to Christos Savva

Re: Moodle extend_navigation_user with custom link

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Christos,

You can add items to the user menu by going to Site Administration > Appearance > Themes > Theme Settings. Look for the User Menu field. No custom programming required.

For more information, see User Menu Items on the following page: https://docs.moodle.org/en/Theme_settings

Hope you find this helpful.

Best regards,

Michael Milette