# Get Only Headings with Kirby Blocks

**URL:** <https://forum.getkirby.com/t/get-only-headings-with-kirby-blocks/21791>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 31, 2021, 7:21pm UTC](https://forum.getkirby.com/t/get-only-headings-with-kirby-blocks/21791 "2021-03-31T19:21:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuwts](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kuwts/32/8190_2.png) [@kuwts](https://forum.getkirby.com/u/kuwts)\
**Post date:** [March 31, 2021, 7:21pm UTC](https://forum.getkirby.com/t/get-only-headings-with-kirby-blocks/21791/1 "2021-03-31T19:21:40Z")

</div>

Hey all,

I’m creating a **table of contents for my Kirby Blocks** field. I am wondering if there is a way to only get the headings (h1, h2, h3, etc) from the blocks field so that I can put them as the href in the table of contents links and as the corresponding ID of the blocks section.

One solution would be to get the level of each block and filter them using an if statement to only get the levels with headings, but I am wondering if there is a simpler way.

Also, I noticed that in Kirby Blocks all headings are outputted as general HTML tags. This is not a massive problem, but if your site has multiple h1 tags, it does affect SEO to a degree.

All tips and help is very much appreciated, thanks 🙂

---

<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:** [March 31, 2021, 7:43pm UTC](https://forum.getkirby.com/t/get-only-headings-with-kirby-blocks/21791/2 "2021-03-31T19:43:03Z")

</div>

You can filter blocks by type:

> **[$blocks-\>filterBy()](https://getkirby.com/docs/reference/objects/blocks/filter-by)**
>
> Alias for Kirby\\Toolkit\\Collection::filter

---

<div class="post-metadata">

**Author:** ![kuwts](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kuwts/32/8190_2.png) [@kuwts](https://forum.getkirby.com/u/kuwts)\
**Post date:** [April 3, 2021, 3:33pm UTC](https://forum.getkirby.com/t/get-only-headings-with-kirby-blocks/21791/3 "2021-04-03T15:33:57Z")

</div>

Thanks, here’s the snippet I used in case it is helpful to anyone:

```
$headings = $blocks->filterBy('type', 'heading');
```
