Snippets/Hide prefix in category

Jump to navigation Jump to search
How to use Snippets
List of Snippets
OOjs UI icon advanced.svg
Hide prefix in category
Language(s): JavaScript
Compatible with: MediaWiki 1.17+ (Vector)


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

<div id="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.


 * Hide prefix in category
 * @source
 * @rev 2020-04-28
$( function () {
    var prefix = $( '#mw-cat-hideprefix' ).text().trim();
    if ( prefix ) {
        $( '#mw-pages a' ).text( function ( i, val ) {
            return val.slice( 0, prefix.length ) === prefix ? val.slice( prefix.length ) : val;
        } );
} );