Knowledgebase

How to display a site notice at the top of pages in MediaWiki

In MediaWiki there are a few ways to display a message at the top of all the pages of your site. The notice is usually shown above page titles, but these is skin-specific; with some skins it may be shown under the page title, or under the page tabs, but in any case it's above the page content. It can be any message you want: e.g. for some site maintenance service that's currently performed, that the site is still in test mode, etc. You can display a notice using all the available ways simultaneously. This doesn't mean that all notices will be shown together. Some of the methods take precedence over the others and so if such an option is used, it's message is displayed instead of the message shown with an option that's considered less important.

You can define and display a site notice using one of the following methods. They are listed according to their weight, meaning that the first in the list takes precedence over the others, and the last one is only shown if the options above it are not defined.

  • MediaWiki:Anonnotice - this is a page on your site (in the MediaWiki namespace) on which you can type whatever message you want to be displayed. What makes it different than the other options is that this message is displayed only when an anonymous user views the site. When the user logs in the message is hidden.

  • MediaWiki:Sitenotice - the notice that you specify on this page is shown on all pages for all users, both anonymous and logged in. Note however that if a notice is specified on the page MediaWiki:Anonnotice, it will be shown (only to anonymous users) instead of the notice defined on MediaWiki:Sitenotice.

  • $wgSiteNotice - this is an option that you can add to the LocalSettings.php file of your MediaWiki. With it you can specify a site notice to be shown on all pages to all users (anonymous and registered). If a notice is defined with the page MediaWiki:Sitenotice, then the notice specified with this option will not be shown.

Now we'll go over each method.

Show a Site Notice to Anonymous Users

If you want a specific notice to be shown only to anonymous users, you can type such a notice on the page MediaWiki:Anonnotice. To open the page simply either type the name in the search field and execute the search, or add the name to the base URL of your site and open it. If, for example, the URL of your site is yourdomain.com, then URL of the page will be yourdomain.com/index.php/MediaWiki:Anonnotice.

After you open the page edit it as any regular page and type for the content of the page the site notice as you want it to be shown to users. It will be displayed above the titles of all pages on the site for anonymous users. After a user logs in, the notice will be removed.

This notice takes precedence over the other options for site notices, meaning that if, for example, you specify a notice with MediaWiki:Anonnotice, and you also specify notices with MediaWiki:Sitenotice and the option $wgSiteNotice in LocalSettings.php, anonymous users will see the site notice specified with MediaWiki:Anonnotice.

The page MediaWiki:Anonnotice can be edited by users who have the editinterface user right. By default, only sysops/administrators have that right.

Show a Site Notice on All Pages to All Users

One way to display a site notice on all pages to all users, regardless whether they are anonymous or logged in, is to use the page MediaWiki:Sitenotice on your site. Just open the page (e.g. yourdomain.com/index.php/MediaWiki:Sitenotice), edit it and for its content type the notice as you want it to be displayed to users.

As with other pages in the MediaWiki namespace, it can be edited only by users with the editinterface user right. By default, only the sysop/admin group has it.

As we mentioned, if there's a site notice specified with MediaWiki:Anonnotice, then it will be displayed to anonymous users instead of the one specified with MediaWiki:Sitenotice. Note however that if you want the site notice defined with MediaWiki:Sitenotice to be displayed to anonymous users, you shouldn't leave the content of the page MediaWiki:Anonnotice empty because this will mean that no notice will be shown to anonymous users. Instead of this for the content of MediaWiki:Anonnotice you should type a hyphen - (this is it's default configuration).

Display a Site Notice with $wgSiteNotice

Another way to add a site notice on all pages for all users (anonymous and registered) is to use the option $wgSiteNotice. You can add it together with the notice to the LocalSettings.php file of your MediaWiki. For example, if you put the following on a new line at the end of the LocalSettings.php file:

$wgSiteNotice = "The site is still being tested";

this will add the message The site is still being tested at the top of all pages. You can use the same code to add any message. Simply replace the text in the quotation marks.

Note that in order for this message to be visible on pages both for anonymous and logged in users, the content of each of the pages MediaWiki:Anonnotice and MediaWiki:Sitenotice should contain only a hyphen symbol -. It shouldn't be blank or contain any text. If these pages contain any text, it will be displayed as a site notice instead of the message specified with the option $wgSiteNotice. If they are blank, no site notice will be displayed.

In case you haven't edited the LocalSettings.php file, you can find it in the root MediaWiki folder on your MediaWiki hosting account. Assuming that the application is installed directly in the public_html directory on your hosting account, making the frontend accessible at yourdomain.com, then the path to the file on the account will be public_html/LocalSettings.php. HostKnox customers can edit it directly on the account with the File manager of the Pixie control panel. Another way to do it is to download it on your local computer, edit it with a text editor (e.g. Notepad ++), then upload it back.

You may also find useful the following articles in our knowledge base:

Was this answer helpful?

 Print this Article

Also Read