Snippets/Hide prefix in category

How to use Snippets
List of Snippets
Hide prefix in category
Language(s): JavaScript Category:Snippets with JavaScript#Hide%20prefix%20in%20category
Compatible with: MediaWiki 1.17+ (Vector)
Category:All snippets#Hide%20prefix%20in%20category

Description

Hide a prefix in the pagenames of category members. Use a Template containing something similar to this:

<div class="mw-cat-hideprefix" style="display: none;">{{{1|{{PAGENAME}}/}}}</div>

And include it like {{MyTemplate|your prefix here}}, e.g.: {{HideCategoryPrefix|your prefix here}}. If the first parameter is left blank, the script will use the title of the category as prefix (useful for categories like Category:Snippets with JavaScript). You may want to redefine that as for your needs.

Code

/**
 * [[Template:HideCategoryPrefix]]
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Hide_prefix_in_category Revision: 2026-03-23
 */
$( function () {
    $( '.mw-cat-hideprefix, #mw-cat-hideprefix' ).each( function ( i, el ) {
        var prefix = el.textContent.trim();
        if ( prefix ) {
            $( '#mw-pages a' ).text( function ( i, val ) {
                return val.slice( 0, prefix.length ) === prefix ? val.slice( prefix.length ) : val;
            } );
        }
    } );
} );
Category:All snippets Category:Snippets with JavaScript