Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Tutorial] Allow more HTML tags in BP forum topics


  • mort3n
    Participant

    @mort3n

    This is how I allowed more HTML tags in my BP forums. Probably there are better ways, but this works for me. Hope it may help someone.

    Problem:
    Per default BP runs the content of forum topics through a filtering function, bp_forums_filter_kses( ) found in bp-forums/bp-forums-filters.php. This function adds some HTML tags to the _few_ allowed by wp_kses( ).

    Effect:
    Formatting, such as lists, are not displayed. The set of allowed HTML tags in forum topics is much smaller than in ordinary WP posts.

    Solution:
    In the functions.php of your theme, perhaps wp-content/plugins/buddypress/bp-themes/bp-default, add a function similar to the default one.
    `function my_forums_filter_kses( $content ){

    $forums_allowedtags = array(
    ‘a’ => array(
    ‘href’ => true,
    ‘id’ => true,
    ‘title’ => true,
    ‘rel’ => true,
    ‘rev’ => true,
    ‘name’ => true,
    ‘target’ => true,
    ),
    ‘abbr’ => array(
    ‘title’ => true,
    ),
    …. and so on to your hearts contend
    );
    $forums_allowedtags = apply_filters( ‘bp_forums_allowed_tags’, $forums_allowedtags );
    return wp_kses( $content, $forums_allowedtags );
    }
    remove_filter( ‘bp_get_the_topic_post_content’, ‘bp_forums_filter_kses’, 1 );
    add_filter( ‘bp_get_the_topic_post_content’, ‘my_forums_filter_kses’, 1 );`

    The last to lines removes the default, overly restrictive, filtering of forum topic posts, the second adds your own.

    Disclaimer:
    By defining your own set of allowed HTML tags you may be opening up for unwanted code being posted to your forums. Be conscious about what tags you allow.

    Cheers
    Mort3n

Viewing 1 replies (of 1 total)

  • Suhas Naik
    Participant

    @suhas-naik

    I am going to use BuddyPress on my site Kenfolios for community building. I am also planning to use BBpress forum along with BuddyPress. Is this trick going to work for BBpress forum too.

Viewing 1 replies (of 1 total)
  • The topic ‘[Tutorial] Allow more HTML tags in BP forum topics’ is closed to new replies.
Skip to toolbar