Hiding Table of Contents on MediaWiki

Adding the following code into your wiki page to toggle the TOC links so that they are collapsed by default.  This is useful if you have a large page and thus a large TOC table.  Obviously you can turn off the TOC links but I find it sometimes useful to skim down the list, so having it collapsed makes it available but not expanded.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<php>
// Hiding the Table of Contents menu since MediaWiki does not provide a way to do it.
?>

<script type="text/javascript">function hideToc() {

var toc = document.getElementById('toc').getElementsByTagName('ul')[0];
var toggleLink = document.getElementById('togglelink');
changeText(toggleLink, tocShowText); toc.style.display = 'none'; } </script>

<script type="text/javascript">hideToc();</script>

<?php
</php>

2 thoughts on “Hiding Table of Contents on MediaWiki

  1. When I put this on the Wiki page and save it, the code just prints on the page. I also tried adding it to LocalSettings.php, but it didn’t work.

Comments are closed.