To summarize this discussion, in order to have HTML in the title field of a node, one needs to either:
1) Use CCK field and a contrib module to override Drupal's title. Drupal titles still appear here and there, so you need to run after each appearance and theme it (hopefully you can)
2) Hack core, specifically check_plain() and a couple other places & modules.

Since I believe this is not such a remote requirement (the nyobserver and my own case are from the news industry), I suggest to have this support in core.

Even if this will not be accepted in core eventually, a patch for such support could be useful.

CommentFileSizeAuthor
#4 211475.patch951 bytesOwen Barton
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drupalchamp@general.motors’s picture

STYLE TITLE OF NODE

Steps needs to be followed:

 Open page.tpl.php of your current theme. In my case it is garland.
 Put the following line of php code snippet.

function bb2html($text) {
  $bbcode = array(
                  "[strong]", "[/strong]",
                  "[b]",  "[/b]",
                  "[u]",  "[/u]",
                  "[i]",  "[/i]",
                  "[em]", "[/em]"
                );
  $htmlcode = array(
                "<strong>", "</strong>",
                "<strong>", "</strong>",
                "<u>", "</u>",
                "<em>", "</em>",
                "<em>", "</em>"
              );
  return str_replace($bbcode, $htmlcode, $text);
}

function bb_strip($text) {
  $bbcode = array(
                  "[strong]", "[/strong]",
                  "[b]",  "[/b]",
                  "[u]",  "[/u]",
                  "[i]",  "[/i]",
                  "[em]", "[/em]"
                );
  return str_replace($bbcode, '', $text);
}
yhager’s picture

Yes, it shouldn't be much more complicated than that piece of code, but page.tpl.php is not where it should reside. Since titles are used also on RSS feeds, page titles, admin screens, views resutls etc.

Owen Barton’s picture

Subscribing

Owen Barton’s picture

Component: theme system » base system
Status: Active » Needs review
FileSize
951 bytes

Here is a patch to allow very very minimal HTML in titles. Will likely break tests, I haven't checked.

This is not core worthy, since I assume we would want some kind of interface to configure valid "inline" tags (or whatever we want to call this), and we would need to parse this and store it in a static. Rather than modifying check_plain we might want to have a check_plain_inline or something, and switch all the node title calls to use this instead. Either way we need to keep this very simple, fast and safe since this function is called a zillion times. Any ideas on where the interface for this might live?

Hopefully this will spark some discussion anyway!

wretched sinner - saved by grace’s picture

Would the best solution to this to use the CCK in Core patch that is in process, and allow input filters to be applied to the title? This would give the best flexibility and reduce confusion for new users. I know when I first started using Drupal that I wondered why some text fields had input filters available and some didn't.

Status: Needs review » Needs work

The last submitted patch failed testing.

Owen Barton’s picture

Status: Needs work » Postponed

Yes - assuming that we get to the point where the node title is a regular field then this would be awesome - by default it is 1 line, text-only - but this way it could be altered to use a filter format (even a multiline, wysiwyg editor if you really want!).

Anyway, let's leave this as a placeholder...

Owen Barton’s picture

Issue tags: +Fields in Core
keddy8’s picture

Subscribing...

mdupont’s picture

sun.core’s picture

Version: 7.x-dev » 8.x-dev
mdupont’s picture

Status: Postponed » Closed (duplicate)

Duplicate of #82751: Allow some HTML tags in node titles. See this issue instead.

apaderno’s picture

Issue summary: View changes
Issue tags: -Fields in Core