How to add meta, link, script, and other elements to the page head

The geek factor on this tutorial is fairly high, so unless you already know what a meta tag is you probably want to skip this tutorial. You have been warned.

Ok... so you have a page that needs a custom meta, link, or script tag in its head. You're stuck because the engineering sites' wrap engine (the scripts that assemble the page) automatically constructs the head elements for each page, and you can't add your own head to the page because then there will be 2 heads in the rendered document. 2 heads are, of course, an abomination.

Fear not; there are ways to do this, and if you already know how to construct the tags you want to add, you won't need any esoteric new knowledge.

link and script tags

You can insert any link meta tags or script blocks that you need by putting them into a head_content property on your page:

  • While editing your page, click on the Properties tab in the ZMI (Zope Management Interface). Note that this solution will not work if your page is a DTML Method, because they don't have a Properties tab. More on that below.
  • On the Properties tab, go to the bottom of the page and add a new property, naming it "head_content" and selecting the "text" type. Don't worry about the value yet.
  • After your head_content has been added, just add your custom tags to the value, exactly as they should appear in the head of the document.
  • Save your changes, and you're done. Load the public view of the page and view the source - you should see your new tags at the bottom of the head element.

meta tags

The wrap engine will check your page's properties to see if 3 specific properties exist:

  • meta_verify_v1  (a key from Google used to verify our ownership of the site)
  • meta_description  (used for improving search results)
  • meta_robots  (tells search engines whether or not to index a page and/or follow the links on the page)

If it finds one of those properties, the value of the property is inserted into the content of the meta tag, replacing the default value.

Note that unlike the head_content property, which inserts it's contents exactly as you enter them, the meta properties insert their values into the content attribute of an existing meta tag. For example:

Property name: meta_description
Property value: This is the description of the page
Resulting tag in the page's head element: <meta name="description" content="This is the description of the page" />

If you type the entire tag into the property value, you'll wind up with a malformed tag like:

<meta name="description" content="<meta name="description" content="This is the description of the page" />" />

Caveats:

If your page is a DTML Method you will first need to convert it to a DTML Document so that it will have properties.

One place where this can trip you up is if you are trying to add head tags to a wrap5 school or program home page. Most of those situations will have a DTML Method named "homepage_content" that is pulled into the site's root "index_html" object. In that case, the property must be added to the home folder's index_html, not homepage_content.

Yeah, I know it's counter-intuitive. Wrap6 should improve things.

-Hilary Mark Nelson, hmnelson@purdue.edu