Is it possible to add a filter to the_content() to group the content? example below

[ad_1]

Hi

Is there any way to add a filter to the\_content() to wrap every H2 title with all the content after it (until the next H2) in a section with an id made from the H2.

So changing this:

<h2>Title 1</h2>
<p>Some text</p>

<h2>Title 2</h2>
<p>Some text</p>

to this:

<section id=”title-1″>
<h2>Title 1</h2>
<p>Some text</p>
</section>

<section id=”title-2″>
<h2>Title 2</h2>
<p>Some text</p>
</section>

Hope it’s clear

Thanks

[ad_2]
1 Comment
  1. “`
    add_filter(‘the_content’, function($content){
    // Your code here
    return $content;
    });
    “`

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer