WordPress allowed_tags() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Helper function

Definition

In WordPress, allowed_tags() returns a text string that lists the HTML tags (and attributes) commenters are allowed to use, such as <a href="" title=""> and <strong>.

The string is already HTML-encoded, so when you echo it the visitor sees the tag names as plain text. It is handy for a small hint under a comment form.

Syntax

It takes no arguments. Echo the result where you want the hint to appear.

WordPress
<?php
echo allowed_tags();
?>
CallWhat it does
allowed_tags()Returns the allowed tags as an encoded string.
echo allowed_tags();Prints the list so visitors can read it.
$allowedtagsThe global array that WordPress reads to build the string.

The function only returns the string. It does not print by itself.

Full declaration
WordPress
allowed_tags(): string

Parameters

ParameterDescription
NoneThis function takes no parameters.

Return Value

Return ValueDescription
stringThe allowed tags and attributes, written as HTML entities, for example &lt;a href=&quot;&quot;&gt;.

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — Show a hint under the form

Tell commenters which tags they may use.

WordPress
<p class="comment-hint">
  You may use these HTML tags:
  <code><?php echo allowed_tags(); ?></code>
</p>

How It Works

  1. allowed_tags() builds the list.
  2. echo prints it inside the <code> tag.
  3. The browser shows the tag names as text, not as real HTML.

Example 2 — Add the list to the comment form

Use the comment form filter to add a note after the form.

WordPress
<?php
add_filter( 'comment_form_defaults', function ( $defaults ) {
  $defaults['comment_notes_after'] =
    '<p class="form-allowed-tags">Allowed tags: ' . allowed_tags() . '</p>';
  return $defaults;
} );

How It Works

  1. comment_form_defaults lets you change the default form text.
  2. We join allowed_tags() into a paragraph.
  3. The page source holds entities, and the screen shows readable tags.

Example 3 — Show it only when comments are open

Do not print a hint on posts that have comments closed.

WordPress
<?php if ( comments_open() ) : ?>
  <small>Allowed: <?php echo allowed_tags(); ?></small>
<?php endif; ?>

How It Works

  1. comments_open() is true when visitors can comment.
  2. The hint is printed only then.
  3. Closed posts stay clean.

Frequently Asked Questions

It returns a string of the HTML tags and attributes that are allowed in comments. The string is HTML-encoded so it shows as plain text.
No. It only returns the string. Use echo to print it.
The tags are encoded on purpose. That makes the browser show the tag names instead of running them.
The list comes from the global $allowedtags array. Changing it is an advanced task, so beginners should only read the list with this function.

Next: bloginfo()

Print site information such as the name, tagline, URL, and charset.

bloginfo() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful