How to use the Custom Tokens module

Last updated on
28 November 2024

Steps to start using the Custom Tokens module:


  • Install and enable the module.
  • Go to "Structure > Custom Tokens". Click "Add token". Enter a name and description.
  • (I don't know what to say about token type. Should we always leave it as "Custom" or are there situations where we'd want to use a different type?)
  • In the "Content" box, enter what you want your token to say.
  • For "Text format" (under the "Content" box):

    • If you want to include a previously defined token in your new token, then use a text format that includes the filter, "Replace tokens".
    • If you want your token to execute some PHP code to decide what it should say, then use a text format that includes the filter, "PHP evaluator" (which requires that the core "PHP filter" module be enabled).
    • Even if your token is just plain text, don't use the "Plain text" format unless you want the token wrapped in <p> ... </p>, because that format will do that.

  • In the "Content" box, wrap any PHP code in <?php ... ?>.
  • If you are using PHP and you want to include a previously defined token in your code, put the token in "token_replace()" (see Replacing Tokens In A String in the Token documentation.)
  • Click "Save". Your new token should appear in the table of custom tokens. The "Demo" column should show the value of your token.
  • If you want to be able to enter your token directly in your webpages instead of just via other modules, then get the "Token filter" module.
  • If you enter your custom tokens directly in your webpages, note that "Custom Token" sends what you put in the "Content" box to the page. It doesn't evaluate it first and then send it. Therefore, if your custom tokens include other tokens and/or PHP code, then the "Body" box in which you place your tokens must use the same text format that you used to define them, so that the other tokens and/or PHP get evaluated.

Credits: the above details are only like a cut-and-paste from issue #2486205: Docu about how to use the Custom Tokens module ... I only "moved" them to what I think is the most appropriate spot for this (great!) docu ... So let the Kudos go to "NewSites" ...

Addition to notes above:

Creation and Use
1) Go to Structure > Custom Tokens > Add Token
a. Give the token a human understandable name eg CompetitionOpenOrClose
b. Give the token a description this is critical as it explains to the end user what the token is used for eg “This token is used to set the competition to Open or Closed when the competition ends simply change the text here to Closed and it will update the site”
c. Leave the Token type as Custom
d. Enter the content you would like the Token to show in this case just the word Open

2) This Custom token is now saved and can be used throughout the site to see a list of all tokens on the site go to /admin/help/token all Custom tokens are found under the Custom list eg [custom:competitionopenorclose]

3) Navigate to the page / area you will be using this Custom Token on and place it where ever it is needed making sure to set “Text format” to Full HTML if you do not set the Text format to Full HTML the token will not be processed and it will just display [custom:competitionopenorclose]

Feel free to delete / edit the above Addition to notes if needed contributed by: BeeOnLion" ...

Help improve this page

Page status: Not set

You can: