Add custom code snippets in <head>
What problem does this address?
Adding custom code snippets on the <head>, <body>, or <footer> elements is only possible using a plugin or by editing the theme files. Some themes support this, but not the Default ones.
What is your proposed solution?
Usually, this kind of functionality is covered by plugins that do a great job but sometimes are abandoned. Establishing a standard way to inject code snippets in the Core, similar to how we can add additional CSS, could complement the full site editing experience.
I propose we start by allowing the users to insert code in a field only for the <head> element, as it is the most commonly used, and iterate from there.
I've reworked #74711 based on what I learned since opening it.
Where it's saved: the first version stored the code in Global Styles. That tied it to the active theme, so switching themes dropped your verification and analytics tags, and resetting styles or restoring a revision wiped it. It's now a single site option, so it stays put no matter which theme is active.
Where it's shown: a "Head code" field on Settings › General. It's a site setting, not a style, so it doesn't belong in the Site Editor's Styles panel.
Behind an experiment: it only loads when Settings › Experiments › Head code is on, and only users with unfiltered_html can see or change it. On multisite that means Super Admins only.
This has come up on Trac before (#6686, #7803) and was left to plugins. Those decisions came from the classic theme era, when every theme had a header.php and a functions.php to edit. Block themes don't, which is why "where do I add my tracking code?" keeps coming up in the support forums.
Feedback welcome!