Help:Magic words - Wikipedia
- ️Sat Oct 31 1987
"H:MW" redirects here. For the MediaWiki namespace, see Help:MediaWiki namespace. For information about the entire MediaWiki software application, see MediaWiki.
Magic words (including parser functions, variables, and behavior switches) are features of wiki markup that give instructions to Wikipedia's underlying MediaWiki software. For example, magic words can suppress or position the table of contents, disable indexing by external search engines, and produce output dynamically based on the current page or on user-defined conditional logic. Some of these features are especially useful for templates.
This page is a quick reference for magic words. For more information, refer to the main MediaWiki documentation:
- mw:Help:Magic words: All standard magic words, including the "standard" parser functions.
- mw:Help:Extension:ParserFunctions: Additional parser functions, including conditional expressions.
General information
In general, there are three types of magic words.
- Behavior switches: often appear in double underscores, all uppercase, e.g.,
__NOTOC__
. They will change the behavior of a page, rather than return a value. - Parser functions: all in lowercase. A parser function will be followed by colon and pipe-separated parameters, e.g.,
{{#ifexpr:Y|Yes|No}}
, wrapped in double braces. They will take a value and return a value. - Variables: these are all uppercase, e.g.,
{{PAGENAME}}
. A variable will be wrapped in double braces and will return a value in its place.
The software generally interprets magic words in the following way:
- Magic words are case sensitive.
- White space is generously allowed for readability. It will be stripped from the start and end of their keywords and parameters (as is also done in template calls using named parameters).
- They can be transcluded, even variables "about the current page". This is ensured by the parsing order.
- Instead of magically transforming into HTML instructions,
<nowiki>
tags remove this magic so a magic word can itself be displayed (documented), e.g.<nowiki>{{#magic:}}</nowiki>
or{{#magic:<nowiki/>}}
.
Magic words compared to templates:
- As with templates, magic words can be transcluded and substituted.
- The names of magic words are purposely chosen to be unlike the names of templates, and vice versa. Many parser function names will begin with a
#
(pound or hash), but template names will not start with a#
, and probably not end in a:
(colon), or be all-uppercase. - The first parameter's syntax differs. In
{{#magic: p1 | p2 | p3}}
, the name is#magic
and it is followed by an unspaced:
and a required input parameter,p1
. With a template,p1
is optional and it is preceded by a|
(pipe) instead of a:
, e.g.{{template|p1}}
.
Most magic words can be used in any needed locations on a page; see MOS:ORDER for guidance on where to place magic words that are behavior switches.
Behavior switches
Variables
"WP:VAR" redirects here. For policies and guidelines with WP:*VAR shortcuts, mostly about style matters, see WP:VARS.
Note: The magic words above can also take a parameter, in order to parse values on a page other than the current page. A colon (:) is used to pass the parameter, rather than a pipe (|) that is used in templates, like {{MAGICWORD:value}}. For example, {{TALKPAGENAME:Wikipedia:MOS}} returns Wikipedia talk:MOS on any page.
Caution: Attempting to use (some) page name variables to create a wikilink to an image page, category page or interlanguage link will produce a different effect: this will respectively place the image on the page, add the page to the category, or create an interlanguage link at the edge of the page. To override this normal behavior, prefix the variable with a colon (
:
); for example [[:{{FULLPAGENAME}}]].
For more details on parser functions that relate to page names and namespaces, see: meta:Help:Page name § Variables and parser functions.
Other variables by type
Universal time | Local-website time | ||
---|---|---|---|
Variable | Output | Variable | Output |
{{CURRENTYEAR}} | 2025 | {{LOCALYEAR}} | 2025 |
{{CURRENTMONTH}} | 03 | {{LOCALMONTH}} | 03 |
{{CURRENTMONTHNAME}} | March | {{LOCALMONTHNAME}} | March |
{{CURRENTMONTHABBREV}} | Mar | {{LOCALMONTHABBREV}} | Mar |
{{CURRENTDAY}}[b] | 19 | {{LOCALDAY}}[b] | 19 |
{{CURRENTDAY2}}[b] | 19 | {{LOCALDAY2}}[b] | 19 |
{{CURRENTDOW}} | 3 | {{LOCALDOW}} | 3 |
{{CURRENTDAYNAME}} | Wednesday | {{LOCALDAYNAME}} | Wednesday |
{{CURRENTTIME}} | 19:01 | {{LOCALTIME}} | 19:01 |
{{CURRENTHOUR}} | 19 | {{LOCALHOUR}} | 19 |
{{CURRENTWEEK}} | 12 | {{LOCALWEEK}} | 12 |
{{CURRENTTIMESTAMP}}[c] | 20250319190143 | {{LOCALTIMESTAMP}}[c] | 20250319190143 |
Parser functions
Metadata
Page IDs can be associated with articles via wikilinks (i.e. Special:Redirect/page/3235121
goes to this page).
To output numbers without comma separators (for example, as "123456789" rather than "123,456,789"), append the parameter |R.
Formatting
Paths
Conditional
If, in these conditional functions, empty unnamed parameters are to be parsed as empty rather than as text (i.e. as empty rather than as the text "{{{1}}}", "{{{2}}}", etc.), they will require trailing pipes (i.e. {{{1|}}}, {{{2|}}}, etc., rather than {{{1}}}, {{{2}}}, etc.).
- For the use of these functions in tables, see Help:Conditional tables.
Other
Substituting and nesting
Magic words can sometimes behave weirdly when substituted or nested. It's possible to subst some magic words (so that the page stops being updated if the value of the word changes). Here are some examples of how this works:
See also
- mw:Localisation
- mw:Manual:Extending wiki markup
- CoreParserFunctions.php
- Preferences → Gadgets → Editing →
(S) Syntax highlighter: Alternative to the default coloring of wiki syntax in the edit box (works best in Firefox and works almost all of the time in Chrome and Opera)
- Special:Version, see last section "Parser function hooks":a list that should include all of the magic words on this page
- {{Ifexist not redirect}}, works with the
{{#ifexist:}}
expression while allowing redirects to be identified and parsed differently
Notes
- ^ If {{FULLPAGENAME}} is used in a page that is transcluded from another page, it will return the name of the target. {{#invoke:TEMPLATENAME|main}} can be used to determine the name of the template itself.
- ^ a b c d e f {{CURRENTDAY}}, {{LOCALDAY}} and {{REVISIONDAY}} return the day (e.g. "6"), whilst {{CURRENTDAY2}}, {{LOCALDAY2}} and {{REVISIONDAY2}} return the day with zero-padding (e.g. "06"). For all two-digit days (i.e. 10 to 31), these are the same.
- ^ a b c These timestamp outputs can be formatted with {{Format revisiontimestamp}} (aka {{FRTS}}). For example, {{FRTS|{{REVISIONTIMESTAMP}}}} turns "20250222065214" into "2025-02-22 06:52:14".
- ^ This shows the last user to edit the page. There is no way to show the user viewing the page with magic words due to technical restrictions.
- ^ a b This function is an expensive parser function.