[Drupal] How to replace a token within the content area of a node in Drupal?

| | 2 min read

One of our Drupal clients was using banner ads for their affiliates to bring in more members. Unfortunately these banner ads were placed inside the content with a page (A Drupal node) and the embed code for the banner ads generated using PHP code by enabling the PHP filter. If you have spent time in the Drupal world you would be knowing that enabling the PHP filter within the content area is a big security vulnerability. So the alternative was to use tokens. Read on to know how to replace a token within the content area of a node in Drupal.

The easy way to replace tokens within the content area in the node is by using the Token Filter
module. Download the module into the sites/all/modules/contrib folder of your Drupal site and then
enable the module.

Now simply enabling the module wont replace the tokens in the content area. We need to add the filter to
an existing or new custom Text Format. To add a new Text format go to admin/config/content/formats/add
in your Drupal site. Add a suitable title for your format and then select the filter.

Replace tokens


You can limit the roles who can use this format by selecting the role. After verifying everything save the configuration.

Once you have created a text format, go to the node were you would want to replace the tokens. For example
I would want to get the user id of the current user and the token for this would be


Place the token in the node and while saving select the Text format from the select list at the bottom of the
node body form and save the node. If you have configured everything correctly you shall be able to see the replaced
value of the token. Cheers!!.