php – Give ID to divs inside the loop

Question

I’m trying to make this code work on my WordPress site:

https://codepen.io/eksch/pen/xwdOeK

It is a simple code so that each menu item receives the active class when the user scrolls through the page, indicating where he is.
But I realize that to make it work it’s necessary to give ID to the divs. My site is made entirely from blocks, which are called in the body of the site via the_content(). WordPress blocks do not allow me to give ID`s to elements.
Is there any way to call the_content() giving an id to each site block? Or some other way to make this work?

My code is extremely simple:

    <div id="content" role="main" class="content-area wrapper-inner main">
        <?php while ( have_posts() ) : the_post(); ?>
             <?php the_content(); ?>;
        <?php endwhile; // end of the loop. ?>
    </div>

0
Eduardo Reis 3 weeks 2021-11-13T16:05:09-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse