How to allow target = “_blank” HTML in BuddyPress forum topic replies

Today, I had the challenge of allowing users to use the target=”_blank” html attribute in BuddyPress forum topic replies. By default, BuddyPress will ignore any target attributes you add to your links.

The secret fix is to tell BuddyPress that you want to allow the target attribute by adding the following code to your functions.php file:

/* Add the HTML  tag attribute 'target' to the list
 * of allowed tags & attributes in BP's activity filters.
 */
function ufmn_add_target_attribute( $activity_allowedtags ) {
	$activity_allowedtags['a']['target']    = array();
	return $activity_allowedtags;
}
add_filter( 'bp_activity_allowed_tags', 'ufmn_add_target_attribute', 1 );
add_filter( 'bp_forums_allowed_tags', 'ufmn_add_target_attribute', 1 );

Pretty neat, eh?!

CREDIT: Literally ALL of the credit for the above solution goes to Dave Ellenwood over at DPE Design.

Posted in ,

Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress consultant, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and then to twitter.com/tobycryns and twitter.com/themightymo

Follow Toby's contributions on Github and WP.org.