Adding HTML Tags to Titles in Drupal
By default Drupal will not rendor HTML tags in a node's title. While the "HTML Title" module works for rendoring the actual node correctly it does not work for printing the title correctly in a view. Here's a little work around I used.
----------------------------------------------------------------------------------------------------------
template.php
----------------------------------------------------------------------------------------------------------
<?php
/* template.php */
function MYTHEME_preprocess_html(&$vars) {
/*make sure to strip out the extra characters for the page title in the <head> tag */
$vars['head_title'] = MYTHEME_strip($vars['head_title']);
}
/* custom functions to convert or strip tags */
function MYTHEME_2html($text) {
$bbcode = array(
"[strong]", "[/strong]",
"[b]", "[/b]",
"[u]", "[/u]",
"[i]", "[/i]",
"[em]", "[/em]",
"[yellow]", "[/yellow]"
);
$htmlcode = array(
"<strong>", "</strong>",
"<strong>", "</strong>",
"<u>", "</u>",
"<em>", "</em>",
"<em>", "</em>",
"<em>", "</em>",
);
return str_replace($bbcode, $htmlcode, $text);
}
function MYTHEME_strip($text) {
$bbcode = array(
"[strong]", "[/strong]",
"[b]", "[/b]",
"[u]", "[/u]",
"[i]", "[/i]",
"[em]", "[/em]",
"[yellow]", "[/yellow]"
);
return str_replace($bbcode, '', $text);
}
?>
----------------------------------------------------------------------------------------------------------
views-view-field-title.tpl.php (or views-view-field--nothing.tpl if you were using a custom field)
---------------------------------------------------------------------------------------------------------
<?php
/* FILE: views-view-field-title.tpl.php (or views-view-field--nothing.tpl if you were using a custom field) */
/*instaed of printing the original, connvert it with our function */
//print $output;
print dailygadsden_2html($output);
?>
---------------------------------------------------------------------------------------------------------
CSS File:
----------------------------------------------------------------------------------------------------------
h1.page-title em{
color:#fae301;
font-style:normal;
}
----------------------------------------------------------------------------------------------------------
Node Creation:
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
Output to screen:
----------------------------------------------------------------------------------------------------------
SOURCE AND ADDITIONAL DETAILS:
http://ryanissamson.drupalgardens.com/blog/html-node-and-view-title
