html in node title - is this possible?

gnotorious - March 13, 2007 - 02:36

Is there any way to allow html in the title field of a node? I realize if I want ALL titles to appear a certain way, I can do that with CSS but what I want to be able to do is italicize JUST one or two words within a title. Basically, the titles of some posts are the proper names of events and my client wants part of the titles to be italicized. Any ideas?

for SEO purposes, im not

VM - March 13, 2007 - 02:46

for SEO purposes, im not sure HTML tags should be inserted into a node title. (someone can of course correct me if I am wrong.)

Italicizing text in a

miana_ed - March 13, 2007 - 02:49

Italicizing text in a regualar html document would not effect SEO. I've never done it, but I don't see any reason why you couldn't with Drupal. I don't know if it will let you though.

Yeah, apparently it does

gnotorious - March 13, 2007 - 02:53

Yeah, apparently it does not. Wondering if anyone has a workaround. Thanks for your responses so far.

It isn't a standard HTML

VM - March 13, 2007 - 02:58

It isn't a standard HTML document though, the title field becomes the title of the page. thus html tags would show to bots no ?

if i title a page <i>home</i> what will strip those html tags when goggle spiders the title for inclusion into search results ?

Drupal doesn't allow this as default , and I was wondering if this is the reason. Especially before user changes the behavior in the manner suggested.

html in title

sampelo - March 13, 2007 - 03:25

I have not found a workaround

Define your own title

styro - March 13, 2007 - 04:37

Basically $title is a phptemplate variable, and these variables can be overridden:
http://drupal.org/node/16383
by changing _phptemplate_variables() in your themes template.php file.

Looking at...
http://api.drupal.org/api/5/function/phptemplate_page
...it looks like it is defined by...
http://api.drupal.org/api/5/function/drupal_get_title

You could write your own copy of the drupal_get_title() function and use it to override $title in your templates by changing the check_plain() function to check_markup() or similar.

I wouldn't recommend removing checks altogether though - you could open up yourself to XSS attacks.

Sorry - I don't have time to show example code at the moment, but i-ligns technology page is an example of where I used a similar technique to slip some markup and section name into the title.

--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ | Project management software knowledge base

Quick untested example

styro - March 13, 2007 - 07:55

In your template.php:

<?php
function  _phptemplate_variables($hook, $vars) {
   switch(
$hook) {
     case
'node' :
     case
'page' :
       
// for page and node templates, redefine the title variable
       
$vars['title'] = mythemename_custom_title();
        break;
   }
   return
$vars;
}

function
mythemename_custom_title() {
 
// customised version of drupal_get_title() that allows some filtered markup
  // uses check_markup() instead of check_plain()
 
$title = drupal_set_title();
  if (!isset(
$title) && function_exists('menu_get_active_title')) {
   
$title = check_markup(menu_get_active_title());
  }
  return
$title;
}

?>

I suspect that will work :)

Note: if your template.php already has a _phptemplate_variables() function, you will need to adapt the above code to it rather than just replacing it.

--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ | Project management software knowledge base

switch with nid

sampelo - March 13, 2007 - 19:37

you can put a switch statement with nid's in template.php

I don't know how that compares with the other approaches here.

Inserting HTML into node titles

markhope - June 13, 2007 - 15:12

what about this example?
http://drupal.org/node/28537

I've used it successfully in 4.7

Mark

HTML in Drupal titles

J. Cohen - August 21, 2007 - 17:54

It also works well on Drupal 5.2. Should work on any PHPtemplate site. I think it's the best option because it doesn't allow HTML directly, but instead uses BBcode.

 
 

Drupal is a registered trademark of Dries Buytaert.