Jump to content

Topic on Project:Support desk

Cavila (talkcontribs)

Although it seems to be poorly documented on this site, most MW skins allow you to specify a banner image as the background for the header. However, what if you (like me) want to be able to choose different header images on a per-page/per-template basis? If, for instance, you have a website about bicycles, cars and helicopters, it would make good sense to have a number of thematic variations on the default header image. The change of image would then be triggered by a template used on the page.

Would it be somehow possible to do this? Or does anyone have alternative ideas? The only alternative I can think of is to change the logo (rather then the header) on a per-page basis using Extension:Logotipo.

Bawolff (talkcontribs)

You can use css perhaps.

For example on vector (in mediawiki:Vector.css)

body.ns-1 #mw-head {background-image: url( http://somewhere/someimage.png );}

Would change the background at the very top of the page to someimage.png for any talk page (talk is namespace 1. All namespaces have there own number. The main (article) namespace is namespace 0).

You can also do per-page changes: </pre> body.page-Extension_Logotipo #mw-head {background-image: url( http://somewhere/someimage.png ); } </pre> would change it on extension:Logotipo only.


If you want to do something in a template, you'd probably need to create a custom extension.

Cavila (talkcontribs)

Thanks. Although I'm not using separate namespaces myself, your first suggestion does look like it could be a workable solution for many users. As for myself, a custom extension would certainly be the way to go. Extension:Logotipo looks childishly simple, but I don’t have any experience with writing code. There at least three extensions which claim to provide custom headers on a per-page basis but just what is meant by 'headers' in those cases is not clear to me and none appears to be fully functional:

Ofbeaton (talkcontribs)

Cavila, My extension HeadersFooters inserts a header/footer into the text of an article before it is parsed. The idea is that you can also insert wikitext and most importantly things like the references tag for cite and it will work. Unfortunately MW is not made to insert text only for the display (and not for edit) at that point, so things are very buggy as I find new cases when editing or saving the text adds the header/footer into the actual article. Once I work them all out, I'll consider it in the beta stage. An extension that doesn't depend on the content of the article would be much simpler, and could be done post-article processing. I'm not sure if the old HeaderFooter extension did this or not, it's certainly more error proof but means that your header/footer has to be free standing (you can't use a cite tag, there are no known citations to list!) I don't see progress being made quickly on my extension but I'm committed to continuing the work as I learn more about MW.

This post was posted by Ofbeaton, but signed as Olivier Beaton.

Cavila (talkcontribs)

Oh, I see, thanks for the explanation.

If you happen to know of a working example, it would be worthwhile adding one to the documentation, but maybe it's too early for that now.

Cavila (talkcontribs)

In the meantime, I found an extension that should do the trick: see Extension:CSS.

Cavila (talkcontribs)

On second thought, wikEd no longers works after Extension:CSS is activated, so it may not be a good idea after all.

Reply to "Dynamic header image"