Quick tutorial explaining how to allow users to include the target attribute (or any attribute) when submitting WordPress posts with USP Pro. Estimated reading time about 5 minutes.

Allow target attribute

To allow target attributes in your post submissions, add the following code snippet via your theme’s (or child theme’s) functions.php file, or add via simple custom plugin:

// USP Pro - Allow custom attributes
function usp_sanitize_content_atts_custom($allowed_atts) {
	$allowed_atts['target'] = array();
	return $allowed_atts;
}
add_filter('usp_sanitize_content_atts', 'usp_sanitize_content_atts_custom');

No edits are required. Once added to your site, the above code tells USP Pro to allow the target attribute in submitted content.

Heads Up: When the target attribute is included on any submitted link, WordPress automatically will add rel="noopener noreferrer". This is a security feature protecting against the _blank target vulnerability.

Allow any attribute

To allow other attributes, first do a test by submitting a post that contains the attributes that you want to allow. If they are removed from the submitted post, then you can allow them by modifying the previous code snippet like so:

// USP Pro - Allow custom attributes
function usp_sanitize_content_atts_custom($allowed_atts) {
	
	$allowed_atts['example']      = array();
	$allowed_atts['data-example'] = array();
	$allowed_atts['target']       = array();
	
	return $allowed_atts;
	
}
add_filter('usp_sanitize_content_atts', 'usp_sanitize_content_atts_custom');

That code adds three attributes, example, data-example, and target to the “allowed” list. So they will be allowed and not removed from submitted posts. You can customize/edit as needed to allow whichever attributes are necessary.