Allow normal user input specific HTML tags in BBPress forum

Allow normal user input specific HTML tags in BBPress forum

Posted: 10 years ago in  Wordpress | BBPress | PHP |


When it comes to bbPress, it is popular plugin to make Wordpress site a powerful forum.


There are also tons of plugins to make it more useful such as WP User Avatar to use Gravatar/Custom Photo as member avatar, GD bbPress Attachment to allow user add file/image in topic/reply, Rating-Widget to allow member rate forum/topic and further more.

However, there is one strict constraint that bbPress apply to replies created by normal members and we could have bad experience with it, that is HTML restriction. Sometime we need those HTML tags and style, then, get these tips to extend bbPress feature.

We can use GD bbPress Tools plugin to disable this restriction or with a slight modification in functions.php of your theme/plugin

Here is my modification of functions.php in my theme to allow <p> tag which is disable by default

function custom_allowed_html_tags() {
    return array(
        // Links
        'a' => array(
            'href'     => array(),
            'title'    => array(),
            'rel'      => array(),
            'target'   => array()
        ),

        // Quotes
        'blockquote'   => array(
            'cite'     => array()
        ),

        // Code
        'code'         => array(),
        'pre'          => array(),

        // Formatting
        'em'           => array(),
        'strong'       => array(),
        'del'          => array(
            'datetime' => true,
        ),

        // Lists
        'ul'           => array(),
        'ol'           => array(
            'start'    => true,
        ),
        'li'           => array(),

        // Images
        'img'          => array(
            'src'      => true,
            'border'   => true,
            'alt'      => true,
            'height'   => true,
            'width'    => true,
        ),
        // Paragraph
        'p'          => array()
    );
}
add_filter('bbp_kses_allowed_tags','custom_allowed_html_tags');

Add more allowed tags and attributes as you need. However, remember to keep the allowed tags at least to avoid it break your template :)