Topic on Project:Support desk

How do I add a new tab on the navigation bar?

8
72.219.238.198 (talkcontribs)

Title is pretty much self-explanatory.

If I'm not being clear, then something like this: http://i.imgur.com/AhqGiky.png

the new tab I would want to create will use external link.

I tried searching for the same question, they had solutions, but most of them didn't work and outdated.

72.219.238.198 (talkcontribs)

I asked someone else who finally gave me the code for this (javascript), this is what I added in MediaWiki:Common.js:

Add a custom tab after "Discussion"

 var ul = document.querySelector(#p-namespaces ul");//finding the list
     var newLi = document.createElement("li");// creating a list item
     newLi.innerHTML = '<span><a href="[insert external link]" title="[insert title]">[tab name]</a></span>';
 
     ul.appendChild(newLi);//adding list item to list

Add a custom tab after "View history"

 var ul = document.querySelector(#p-views ul");//finding the list
     var newLi = document.createElement("li");// creating a list item
     newLi.innerHTML = '<span><a href="[insert external link]" title="[insert title]">[tab name]</a></span>';
 
     ul.appendChild(newLi);//adding list item to list
92.15.242.136 (talkcontribs)

Hello there Would you know where I could find this JS you edited please, I just can;t seem to find it :( Thank you

Stargy (talkcontribs)
92.15.242.136 (talkcontribs)

Thank you Stargy, I appreciate. I followed the link on my wiki (I own both wiki and site), and copied and pasted your code on that page but all I get is a copy of the text, no action on the menu has taken place. I feel so inadequate here with wiki language, I know css and html, but wiki stuff is real new to me and instructions here are so jargonic. Thank you though

Florianschmidtwelzow (talkcontribs)

If you're the wiki operator and can install extensions, you could also use a server side method. Create a new extension (e.g. using this Manual) and add a hook listener for the SkinTemplateNavigation hook. As a hook handler you could use the following code to add a new tab after the discussion (or to be more precise: after the last tabe of a page) tab:

public static function onSkinTemplateNavigation( SkinTemplate &$sktemplate, array &$links ) {
    $links['namespaces'][] = array(
        'class' => 'test', // a css class, if you want
        'text' => 'Testtab', // That's the text visible to the user, you might want to use a message key, instead of a hardcoded text
        'href' => 'test', // That's the link the tab will redirect to, when clicked
    );
}
Reply to "How do I add a new tab on the navigation bar?"