Insert code directly below <head>, or two sets of <head> tags

I need to insert some code directly below the opening <head> tag. Adding the code to the usual head section in settings isn’t working, as RW adds the code between the <head> </head> tags, but not as the first item.

Does anyone know of a way to solve this?

I know I can add the code manually, but I know that at some point I’ll republish the page, forget, and so break the page.

I have found that one solution is to add <head> code here </head> to the prefix, but of course that will then result in two sets of head tags. I know officially this is not a good idea, but I’m wondering how bad an idea it is. I know I’ve done things like this in the past and seen no side-effects, but I also know browsers are far less forgiving nowadays, and Google is a bugger for things like this now, so I’d appreciate some opinions.


If you have jquery in scope then you can retrofit the element using something like:


Not knowing what you’re adding to the head section makes it difficult to say for sure.

I wouldn’t add two head sections, since that’s technically an error you don’t know what impact it has or will have in the future. Even though it might seem to be okay today the next update to a browser could “break” it.

Is what you are putting in the head section static on every page? If so have you thought about changing the theme?

I’m using UIkit, and changing the framework isn’t an option.

The code to be inserted is this: <base href="" />

It’s purpose is to fix any CSS issues after applying some SEO tricks to the htaccess file pertaining to a PHP script on the page.

It works perfectly, but only if inserted as the very first thing in the head section.

Adding the following to the prefix works, but as discussed, not keen on having two head section.

<html lang="en-gb" dir="ltr">
 <head><base href="" /></head>

@indridcold That’s an interesting idea, but I’m clueless on such things. Are you able to help?

I did some Googling, and I think it might be possible to add it in the correct place using some PHP, but again, even though I found some potentially suitable code, I couldn’t work out how to make it work.

All help appreciated.

Tagging: @Lucas

1 Like

Don’t know why that wouldn’t be an option. I don’t have UIKit but the Theme on most frameworks are much simpler than the themes on traditional Themes. Unless UIKit changes the theme a lot I don’t see why that would be an issue

Never heard of that before. The Specs doesn’t mention this, so the PHP script that’s using this must not be finding it if it’s in another location.

I wouldn’t consider having two head sections, over have of web traffic is “non-human” or screen-readers. Having two head sections will probably break something you haven’t even thought of. Plus the code you show above looks to add an additional <html tag? That’s another error.

Adding post page load(Javascript or jQuery) probably won’t work. Don’t know for sure, but the PHP script would have already done its thing (PHP is Server-side) prior to JavaScript(Client-side) executes.

Is this only for a single page?

If it’s for a single page, I’d change the Theme for that single page.

I don’t have UIKit but here’s how with Foundry:

  1. Duplicate the theme2020-03-14_10-37-38
  2. Right-Click the duplicate and select Show in Finder 2020-03-14_10-43-10
  3. In most themes, the base HTML is in index.html. Open with a text editor2020-03-14_10-45-00
  4. Make the changes to that and save

Set the theme for the one page to the copy.

1 Like

Changing the theme isn’t an option.

At present I’ve added the code into the position needed manually, but I like the idea of editing the base theme. Good idea.

1 Like

SEO Helper allows you to place meta tags inside head. It even has out of the box support for the base meta tag…

Have you a link to page using SEO Helper?

Another option would be to duplicate the UIkit theme first, then on the duplicated theme move the %user_header% to where you want it to be, right under the <head> tag.


Sounds the perfect solution.

I want to add this bit of code to a lot of uikit projects, so I’ll use the edited theme on all these.

Thanks folks.

Just ran some tests, and works perfectly.

I’m now curious, is there any reason not to always put user_header at the top of the head section?

All of Weaver’s Space uses SEO Helper. Seems like you are going to be modifying the theme though. Good luck!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.