Post-Header A simple PHP function to remove duplicate UTF-8 meta tag for Drupal Generated Page.

I was converting an existing XHTML page to Drupal CMS themes when I noticed that there was a duplicate output for UTF-8 meta tag that was generated by Drupal. This was not a big issue but for me it was so ugly and I don't want this meta duplication. At first I thought of it as a bug but when I search for this duplicate UTF-8 meta tag seem's it was intentionaly inserted by Drupal developer for security reasons and for the sake of all un-updated Drupal themes.

Here's what the ugly generated UTF-8 code look like in my XHTML page:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link rel="shortcut icon" href="/misc/favicon.ico" type="image/x-icon" />

Looking for the best way to avoid this duplicate meta tag that was generated by Drupal, I found this PHP code snippet that can be easily inserted to your template.php file and viola, UTF-8 meta duplication is gone.

and here's the code that you need to insert to your template.php file:

  <?php
 
function THEME_NAME_preprocess_page(&$vars) { //remove duplicate utf-8 meta
 
$vars['head'] = preg_replace('/<meta http-equiv=\"Content-Type\"[^>]*>/', '',
 
$vars['head']);
  }
 
?>

 

Please note that if your theme doesn't have a template.php file you must create it first and then insert the snippet code above, you need also to change the THEME_NAME in the PHP function name with the name of your theme. Here's an example equivalent code when I inserted it to my template.php file:

  <?php // $Id
function danreb_preprocess_page(&$vars) { //remove duplicate utf-8 meta
$vars['head'] = preg_replace('/<meta http-equiv=\"Content-Type\"[^>]*>/', '',
$vars['head']);
?>

 

I replace THEME_NAME with the name of my theme and inserted it at the second line of my template.php file.

Source : http://drupal.org/node/451304

Drupal Themes Variable snapshot :

<?php print $head_title ?> // must be inserted inside the
                              title tag <title>here</title>

<?php print $head ?> // insert right after the title tag -
                        responsible for some code needed inside
                        the head like the link for favicon
 

<?php print $styles ?> // code that insert all the stylesheets,
                          insert after the print $head
 

<?php print $scripts ?> // code that insert all the javascripts ,
                            insert it after the $styles
 

That's it for now, more themes variable snapshot soon.....

Search
User login
Who's online
There are currently 0 users and 0 guests online.
Who's new
  • Annabel
  • jsm
  • jito14
  • tine
  • abz_i
Guest Shoutbox
There are no shouts to view.
Login or register to post shouts
All Shouts
Recent comments
New forum topics
Syndicate
Syndicate content