I'm facing an issue where I'm attempting to programmatically set the description property for a taxonomy term that includes HTML, but the HTML is being rendered as text, rather than being rendered into HTML elements, unless I manually access the term in a browser and save it.


  'name' => $name,
  'description' => $t('<h5>My description.</h5><p>More info.</p>'),
  'vid' => $vocab->vid,

When I attempt to render the description, it appears as:

<h5>My description.</h5><p>More info.</p>

However, if I then go to Structure > Taxonomy > My_Vocabulary > My_Term and simply save the term (without any edits), it will then render properly as:

My description.

More info.

I've also made a number of attempts to achieve this through an Entity Metadata Wrapper, but no luck (though I am admittedly not well versed on EMWs).

How can I programmatically force the description to correctly render the HTML without having to manually re-save it?

Any help is appreciated!

  • Just on mobile so can't check - isn't there a format property can you set to full_html, or the name of another more permissive filter? – Clive Sep 30 '16 at 8:22
  • From what I can tell, there is no format property because Description is an entity property, rather than a field (corrections to any misunderstanding are welcome!). – Beau Sep 30 '16 at 9:26
  • @Clive, I take that back. I was so focused on the idea that the format property belonged to the Description that I didn't think to look at the term itself. There is indeed a format property that I completely overlooked as part of taxonomy_term_save(). Please post this as an answer so I can give you credit. – Beau Sep 30 '16 at 9:49
  • Just got back to the computer and answered as it happens :) – Clive Sep 30 '16 at 9:50

The taxonomy_term_data table, which is the entity table for taxonomy terms, has a format column which stores the name of a filter to apply to the description when rendered.

It's available as a property on the entity, so you can use:

  'name' => $name,
  'description' => $t('<h5>My description.</h5><p>More info.</p>'),
  'vid' => $vocab->vid,
  'format' => 'full_html',
| improve this answer | |

Use the format property:

$term = taxonomy_term_load($tid);
$term->description = t('<pre><strong>Text</strong></pre>');
$term->format = 'full_html';
| improve this answer | |
  • this is also great information and I'm grateful for it! It just happens to be that Clive beat you to it. :-) – Beau Sep 30 '16 at 10:00
  • It's not about beating or losing, we all learn and help each other. Remember that you can always reward a good answer not only by accepting it but by up-voting it in either case ;) I up voted Clive's answer while you didn't , see what I mean ? – mchar Sep 30 '16 at 10:06
  • Actually, I did upvote his answer (and yours), but my reputation is too puny to count. :/ – Beau Sep 30 '16 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.