Only display TinyMCE on certain node types in Drupal

This example will show you how to choose which node types use the TinyMCE module.

Goto Admin > Site configuration > TinyMCE

Click edit next to your profile.

Under the Visibility field group, select Show if the following PHP code returns TRUE (PHP-mode, experts only).

Enter the following code::

# enter the node types that will use TinyMCE
$allowed = array('book','page','forum');

$use = FALSE;
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(array('nid' => arg(1)));
  if (in_array($node->type,$allowed)) {
    $use = TRUE;
  }
}
foreach($allowed as $type) {
  if (strpos(request_uri(),"node/add/{$type}")){ $use = TRUE;}
}
return $use;

Thats all!

Now you can change the value of $types = array('book','page','forum'); to decide where to display TinyMCE.

Post new comment

  • Allowed HTML tags: <b> <br> <p> <a> <strong> <cite> <em> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You may use [img:xx] tags to display uploaded files or images inline.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <css>, <diff>, <drupal5>, <html>, <javascript>, <php>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options