# How to add class to kirbytext

**URL:** <https://forum.getkirby.com/t/how-to-add-class-to-kirbytext/15962>\
**Category:** Questions\
**Tags:** v3\
**Created:** [October 16, 2019, 9:44am UTC](https://forum.getkirby.com/t/how-to-add-class-to-kirbytext/15962 "2019-10-16T09:44:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/johan/32/7322_2.png) [@johan](https://forum.getkirby.com/u/johan)\
**Post date:** [October 16, 2019, 9:44am UTC](https://forum.getkirby.com/t/how-to-add-class-to-kirbytext/15962/1 "2019-10-16T09:44:26Z")

</div>

Hi,

I’m trying to add a class “paragraph” to the `<p>` tag when calling kirbytext:  
`<?= $post->text()->kirbytext() ?>`

I found this solution for Kirby 2, is this still the preferred way to go or has anything changed in Kirby 3 to make this easier?

> [@How do I add a class when calling kirbytext?](https://forum.getkirby.com/t/how-do-i-add-a-class-when-calling-kirbytext/5283/2):
>
> 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\>

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 16, 2019, 9:50am UTC](https://forum.getkirby.com/t/how-to-add-class-to-kirbytext/15962/2 "2019-10-16T09:50:21Z")

</div>

Kirby now has the `kirbytextinline()` method. But note that both the method and the above code remove all `p` tags. So it doesn’t really make sense for multi-paragraph text.

Why do you need a class on the `p` tag? How about wrapping the text inside a div and target the `p` tags inside the div via the class applied to the div?

```auto
<div class="text">
<?= $post->text()->kirbytext() ?>
</div>

```

```auto
.text p {
  /* styles */
}

```

Best solution depends on your use case.

---

<div class="post-metadata">

**Author:** ![johan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/johan/32/7322_2.png) [@johan](https://forum.getkirby.com/u/johan)\
**Post date:** [October 17, 2019, 6:43pm UTC](https://forum.getkirby.com/t/how-to-add-class-to-kirbytext/15962/3 "2019-10-17T18:43:54Z")

</div>

Thanks that makes sense!
