[Tutorial] Allow more HTML tags in BP forum topics
-
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
You must be logged in to reply to this topic.