Drupal: Replacing self-closing tags

Drupal is an open source platform that allows you to build various types of web sites without the need of knowing web programming languages. It is relatively easy to install and has loads of different modules, which give you extensive flexibility in designing you Drupal site. One of them is called FCKEditor. FCKEditor replaces the regular content editing boxes that come with the Drupal installation with a very powerful WYSIWYG ("What You See Is What You Get") editor.
Blogs, wiki sites, simple web sites and even fully featured commercial sites, all can be built using Drupal, but don't worry, this is not a commercial for Drupal :)...

There are some things I encountered during my work that Drupal together with FCKEditor do not support. An example is support for pure HTML pages and not XHTML pages. These are used mainly for emailing and other purposes.

Drupal automatically inserts to the <head> section of your web pages the "Content-Type" meta tag using the XHTML standard:

<meta http-equiv="Content-Type" CONTENT="text/html; charset=utf-8" />

By XHTML I mean the way this tag is a "self-closing" tag (it has a /> at the end and not just >).
To this point I haven't found a module that allows me to customize this. Furthermore, I have found out that this is hard-coded in the Drupal core files, so I don't think there is a module that can change this.

In order to solve this problem (and more) you'd have to get yourself familiar with PHP code. Like any other programming language, it is quite simple once you learn the basic syntax.

Solution: Before we go to the solution, please read carefully the following notes:

  • The following solutions are based on the Drupal core version 6.14 and FCKEditor module version 2.6.5. It may differ for different versions.
  • Please use these solutions with extra care, since they tamper with the Drupal core code and the Drupal site's theme code. Any mistakes and the whole site will be down!

Now, the PHP code that inserts this meta tag lies inside a file called common.inc. You can find it in the ROOT/includes/ folder of your Drupal site.
Search for the drupal_get_html_head() function and there you will see two lines:

$output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
return $output . drupal_set_html_head();

Simply comment these two lines out (add // at the beginning of the lines) and add a new line underneath:

return drupal_set_html_head();

Next, search for drupal_final_markup() function and there replace the closing slash in the line (replace /> with >):

return preg_replace('/<head[^>]*>/i', "\$0\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />", $content, 1);

You should see this line like this:

return preg_replace('/<head[^>]*>/i', "\$0\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">", $content, 1);

Another thing that Drupal (or maybe FCKEditor) does in the context of XHTML is the line-break tags: <br /> instead of <br> and image tags: <img ... /> instead of <img ... >.

The solution is similar. Simply replace all the occurrences of /> with > inside the page. But this is not part of the Drupal core, so how do we do it?
Simple, as always... You need to go into the template files of your Drupal site's theme (usually named <something>.tpl.php) and find every usage of the $content or $block->content.
Usually the theme has a node.tpl.php and block.tpl.php files (tpl stands for template, obviously).

Inside the node.tpl.php file, find the place(s) where the $content variable is used (usually a print command will appear before it) and replace it with the PHP function for replacing strings: str_replace(...).
Inside the block.tpl.php file, do the same for $block->content.

For example, inside node.tpl.php replace:

print $content;


print str_replace(" />",">",content);

And inside block.tpl.php replace:

print $block->content;


print str_replace(" />",">",$block->content);

Good luck!

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.