A function that will strip out any unwanted tags from a string.
<?php
/**
* Remove everything from a string except the tags specified below
*/
function cleanText($text) {
$text = strip_tags($text, '<em>, <br>, <u>, <span>, <strong>, <sup>');
return $text;
}
Place this code in your functions.php file (or import it in via the functions folder).
Handy when you need to you have a title that requires special styling in the backend (Ex: A different coloured word in a title). For example:
<?php $title = get_sub_field('title'); ?>
<h2><?= cleanText($title); ?></h2>