Duplicated tag in loop

I stuck on this issues, looks simple but can’t find resolution to fix it.

I have such loop:

<div class="features-items__wrapper">
                <h2><?php echo $currentTitle; ?></h2>
                <?php
                global $post;
                $post_slug = $post->post_name;
                $args = array(
                        'posts_per_page' => -1,
                        'post_type' => 'feature',
                        'order' => 'ASC',
                        'tax_query' => array(
                          array(
                           'taxonomy' => 'feature_сategory',
                           'field' => 'slug',
                           'terms' => $post_slug
                          )
                         )
                    );
                $the_query = new WP_Query( $args );
                ?>
                <?php if( $the_query->have_posts() ): ?>
                <?php
                    $counter = 0;
                    $total = $the_query->post_count;
                    while ( $the_query->have_posts() ) : $the_query->the_post();
                    if ($counter % 2 === 0) {
                ?>
                <div class="row">
                <?php } ?>
                    <a href="<?php the_permalink(); ?>" class="features-items__item col-12 col-xl-6">
                      <div class="features-items__img">
                        <img src="<?php the_field('feature_item_icon'); ?>" alt="">
                      </div>
                      <div class="features-items__description">
                        <h3><?php the_field('feature_item_title'); ?></h3>
                        <?php the_field('hero_subtitle'); ?>
                      </div>
                    </a>
                <?php $counter++; if ($counter != 0 && ($counter % 2 === 0 || $counter === $total)) { ?>
                </div>
                <?php } ?>
                <?php endwhile; ?>
                <?php endif; ?>
                <?php wp_reset_query(); ?>
              </div>

And i get such output: https://prnt.sc/100lsjh
And makrup: Duplicated <a> tag in loop

As you see markup is broken and it’s because second feature has link inside (field hero_subtitle has WYSIWYG editor type)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Seems like one of your ACF fields contain a <a> tag in them.

In HTML you cannot have and <a> tag inside another <a> tag.

Check the ACF fields the_field('feature_item_title') and the_field('hero_subtitle'), check their content, most likely you will find a <a> tag in one of them, remove it and your html will be structured correctly


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x