Knowledgebase

How to remove personal user links from the header in MediaWiki

In MediaWiki there are some personal user buttons related to the account of the user and to logging in and creating accounts. Usually they are displayed at the top of the page, in the header of the site, but this depends on the skin. Some skins may show them, for example, in the left column.

For anonymous users (users that are not logged in) the personal buttons that are displayed are:

  • Create account

  • Log in

  • the button for accessing/creating the personal page of the user (it's labeled with the IP address of the user)

  • Talk for this IP address link which opens the discussion page associated with the personal page of the user

The personal links normally shown to logged in users are:

  • the link to the personal page of the user; it's labeled with the account username of the particular user

  • Talk

  • Preferences

  • Watchlist

  • Contributions

  • Log out

If you want to, you can remove any of those links from being shown. There are different ways you can do that. One is to add the option $wgHooks in the LocalSettings.php file and use it to add a hook that unsets the particular link(s). Another way is to hide the links using CSS (Cascading Style Sheets) modifications. In this article we'll go through these methods.

When it comes to removing the IP address that links to the personal page of the visiting anonymous user and to the link Talk for this IP address that opens the corresponding discussion page, it's also possible to remove them with the options $wgShowIPinHeader and $wgDisableAnonTalk. For more information on this check out the article on how to disable the links to talk pages and user pages of anonymous users in MediaWiki.

Note that each of these methods only removes the links, it doesn't stop the access to the corresponding pages. The pages can still be accessed either by directly opening the URL of the page, or by using a link to that page that's available elsewhere on the site (e.g. on the Special pages list).

Remove Personal User Links with the Option $wgHooks

With the option $wgHooks you can add a hook in the LocalSettings.php file of your MediaWiki that unsets any of the personal links, so that they don't appear on the frontend of the site. This works for all skins. For example, by adding the following at the end of LocalSettings.php:

$wgHooks['PersonalUrls'][] = 'lfRemoveUserLinks';
function lfRemoveUserLinks( &$personal_urls, $title ) {
        unset( $personal_urls['watchlist'] );
        unset( $personal_urls['userpage'] );
        unset( $personal_urls['mytalk'] );
        return true;
}

you'll remove the links Watchlist, Talk and the one for accessing the personal user page. These are links that are shown to logged in users.

Each unset line in the code specifies a particular link to be removed. The label/key of the link is in quotation marks in the square brackets. For example, the label userpage stands for the link that opens the personal page of the user. These labels are defined in the file SkinTemplate.php of your MediaWiki. To make it easier for you we'll list them here:

createaccount - the link for creating accounts (for anonymous users)

login - the Log in link

userpage - the link to the personal page of logged in users

anonuserpage - the link to personal user pages of anonymous users. The IP address of the user stands for the name of the link and of the page respectively.

mytalk - the Talk link that opens the discussion page of the logged in user

anontalk - the link to the discussion pages of anonymous users. On the frontend the link is labeled Talk for this IP address.

preferences - the Preferences link that displays the account options of the user

watchlist - the link to the watchlist of the user

mycontris - the link Contributions that shows what page contributions the user has made

logout - the Log out link

To remove particular links you can use the above code and simply add an unset line for each link and in the square brackets put the label of the link. For example, if you want to remove the links for creating accounts, for logging in and those for the personal and discussion pages of anonymous users, you have to add the following to LocalSettings.php:

$wgHooks['PersonalUrls'][] = 'lfRemoveUserLinks';
function lfRemoveUserLinks( &$personal_urls, $title ) {
        unset( $personal_urls['createaccount'] );
        unset( $personal_urls['login'] );
        unset( $personal_urls['anonuserpage'] );
        unset( $personal_urls['anontalk'] );
        return true;
}

If you haven't edited the LocalSettings.php file and you don't know where it is, you can find it in the root MediaWiki folder on your MediaWiki hosting account. Assuming the application is installed directly in the public_html directory on the account, the path to it will be public_html/LocalSettings.php. HostKnox customers can use the file manager of the Pixie control panel to view and edit files. Another way is to download the file on your local computer, edit it with a text editor (e.g. Notepad ++) and upload it back replacing the old file.

Remove Personal User Links with CSS Modifications

Another way to hide personal user buttons is with some simple CSS modifications. Regardless of which button you want to remove, the code has the same form:

element { display: none!important; }

where element has to be replaced with the actual ID for the particular link. Note that the IDs are skin-specific. Although most skins may use the same ID for a particular button, some may use a different one.

You can add the modification(s) to the page MediaWiki:Common.css of your site (e.g. yourdomain.com/index.php/MediaWiki:Common.css. This will affect all skins, provided that they all use the specified ID. If you want only a particular skin to be affected, you can add the change just to its corresponding page (e.g. MediaWiki:Vector.css for the Vector skin). For more general information on this check out the article on how to make CSS modifications in MediaWiki.

Here we'll list the IDs for the different personal user links, together with the CSS code for removing that particular link. We've used as an example the skins: Vector, MonoBook, Modern, Cologne Blue. The IDs are the same for all four skins.

#p-personal { display: none; } - this removes all personal links. Note that with the Cologne Blue skin, unlike the other three example skins, most of the personal user buttons are located in the left column and not in the header. In the header are only the links Create account, Log in and Log out. So when it comes to the Cologne Blue skin this code removes the links in the left column; the links Create account, Log in and Log out are not affected.

#pt-anonuserpage { display: none!important; } - removes the link to the personal user page of anonymous users. As you know this link is labeled with the IP address of the user viewing the site.

#pt-anontalk { display: none!important; } - hides the link Talk for this IP address. That's the link with which the anonymous user that's viewing the site can access their personal discussion page.

#pt-createaccount { display: none!important; } - removes the link Create account for making new accounts.

#pt-login { display: none!important; } - hides the link Log in.

#pt-userpage { display: none!important; } - removes the link to the personal user page of the logged in user.

#pt-mytalk { display: none!important; } - removes the link Talk that opens the discussion page of the logged in user.

#pt-preferences { display: none!important; } - hides the Preferences link that opens the the page with the account options of the user.

#pt-watchlist { display: none!important; } - removes the link for the watchlist.

#pt-mycontris { display: none!important; } - removes the link Contributions that opens the list with the page edits made by the particular user.

#pt-logout { display: none!important; } - removes the Log out link.

Some other articles with CSS modifications in our knowledge base that you may find helpful:

Was this answer helpful?

 Print this Article

Also Read