How to remove "preferences" from User Menu

How to remove "preferences" from User Menu

by Andrew Lian -
Number of replies: 7

Hello

I notice that I can manipulate the content of the dropdown user menu quite easily (add or remove items), but it looks like the " Preferences" menu item is added automatically and cannot be removed. I would like to remove it. Any idea of how to do this? I am using moodle 4.x

Thank you for your help

Andrew

Average of ratings: -
In reply to Andrew Lian

Re: How to remove "preferences" from User Menu

by Randy Thornton -
Picture of Documentation writers
There seems no way to be able to manage or remove the items below the first divider line, only those above it. Preferences, Language (if enabled), Switch to role are added automatically, just like Log out. (The documentation on the theme setting page for this is clearly incorrect.) There is also no specific id or class for those items in the css, so that is not an option either.

I think possible options to fix this would be to edit the core code to remove that option or to use a theme that works in 4.0 that does allow you to control the menu. Several themes have allowed you to control this in the past. You might try looking at the themes available so far for 4.0.
In reply to Andrew Lian

Re: How to remove "preferences" from User Menu

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Do you really want to remove the menu or just to stop users from changing the options within it?
In reply to Andrew Lian

Re: How to remove "preferences" from User Menu

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers
There is no need to edit the core code. You can target attributes in CSS as well as IDs and classes. Add this to the custom css in the theme:

.usermenu a[href$="preferences.php"] {
    display: none;
}
Average of ratings: Useful (3)
In reply to Jon Bolton

Re: How to remove "preferences" from User Menu

by Randy Thornton -
Picture of Documentation writers
Jon,

Nice! I stand corrected, that is a nice way to do it in css. I had not thought about using the href$ there.
In reply to Randy Thornton

Re: How to remove "preferences" from User Menu

by Andrew Lian -
Thank you all so very much. The href$ solution works fine (until some day I decide that someone or some course needs access to preferences - but it won't be for a while).

And, Howard, I was just trying to remove the menu item not the menu.
Thanks all once again
Andrew
In reply to Randy Thornton

Re: How to remove "preferences" from User Menu

by Randy Thornton -
Picture of Documentation writers
For the record, the syntax above works with preferences.php since it is at the end of href. But the Switch role and Logout menu options are built with custom parameters for the hreft on the fly: eg. Logut has a parameter with your unique session id in it. Instead you can also use a[href$^= or a[href*= to get around this. Documentation on this at: https://www.w3.org/TR/selectors-3/#attribute-substrings
In reply to Jon Bolton

Re: How to remove "preferences" from User Menu

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Hi Jon, your solution to removing Preferences is very clever and cool. I never thought that one could do this via CSS.

This makes me wonder if I could remove the "Course Index" from Moodle 4.0 using the same technique. Chris removes it in his LearnR theme. I am not sure how.

Do you have anything thoughts about how to remove the "Course Index" feature, meaning the entire left-side flyout column, from Moodle 4.0? Thanks.

Quick Update: In my quick experimenting, I came up with the following CSS, which hides the button.  Logic: If the button is never available, there is no way for the student to see the Course Index. I put this CSS into the Raw SCSS textbox for Boost.

.drawer-toggles .drawer-left-toggle .btn {
  display: none;
}