Topic on Project:Support desk

How do I add attributes to the <html> or <head> elements?

Psychonaut (talkcontribs)

I am running MediaWiki 1.34.2. What code do I need to add to my LocalSettings.php to add a new attribute to the <html> or <head> element? For RDFa compliance I need to add a prefix attribute so that the associated value will be recognized in the <meta> tags I've already added via addMeta().

Ammarpad (talkcontribs)
Psychonaut (talkcontribs)

According to the documentation, that hook is "Called when OutputPage::headElement() is creating the body tag". By the time the <body> tag is output, isn't it too late to change the <html> and <head> tags? Or am I misunderstanding something?

MarkAHershberger (talkcontribs)
Psychonaut (talkcontribs)

Hm… that's not a very generalizable solution, is it? What if I just want to properly add, say, Open Graph metadata to my wiki? Is the only solution to fork all the skins available on my wiki for the sole purpose of adding prefix="og:" to the <html> tag, and then make sure that I keep all those skin forks in sync with future releases?

Ciencia Al Poder (talkcontribs)

Extension:OpenGraphMeta adds opengraph metadata without declaring that namespace, and social media have no problem in parsing this data so far.

Namespace declaration can be done in the parent element, or in the element itself. This means you can also declare that namespace in the elements you are going to produce instead of declaring it in the root. Of course, that's not ideal when you need to use multiple elements and repeat the same namespace several times.

Submitting a patch or bugreport it is the way to get this fixed.

Psychonaut (talkcontribs)
Reply to "How do I add attributes to the <html> or <head> elements?"