Template:DefaultSort

Usage:
 * custom default sort value (optional)

This template adjusts the default sort of a page (i.e. how it's sorted in categories), taking the place of the magic word.

It will automatically treat the page title as a person's name to alphabetically sort by surname. If added to the page with no parameters, it takes the page title's last word (the contents after the last space), followed by a comma and a space, followed by the rest of the page title (the content before the last space). E.g. adding undefined to the page for "John J. Smith" will have the page alphabetically sorted in categories as "Smith, John J.".

What's actually added to the page:

Note that individuals whose surnames consist of two or more words separated by a space will need to be fixed manually:

Test how a page will be sorted by default with  or. Note that this is not meant to be saved on a page, but only to preview to confirm how the page will be sorted.

The template will only read the page name, not the namespace, e.g. "Template:" will not be included when using in the Template namespace.

See also:
 * https://www.mediawiki.org/wiki/Help:Magic_words#Defaultsort