How do I add a class when calling kirbytext?

Put the below code into a file in /site/plugins:

function ktRaw($content) {
  $text = kirbytext($content);
  return preg_replace('/(.*)<\/p>/', '$1', preg_replace('/<p>(.*)/', '$1', $text));
}

field::$methods['ktRaw'] = function($field) {
  return ktRaw($field->value);
};

The function removes the p-tags from content.

Then in your template, call the new ktRaw() field method:

<p class="testimonial__body"><?php echo $page->testimonial()->ktRaw() ?></p>
1 Like