PHP within anchor’s divs causing undesired output

Looking for some rookie PHP direction here. I’m in wordpress, working on a child theme file.

Trying to wrap an anchor around a chunk of divs with php tags in them, but the output results in two empty anchors out of order. Removing the PHP results in the correct html output.

Just looking for a hunch on what’s wrong…

PHP

<div <?php post_class(); ?>>
    <?php
    echo '<a class="featured-image-link" href="' . esc_url( get_permalink() ) . '">';
    ct_tracks_featured_image();
    echo '</a>';
    ?>
</div>
<a href="#">
    <div class="excerpt-container">
        <div class="excerpt-meta">
            <?php get_template_part( 'content/post-meta' ); ?>
        </div>
        <div class="excerpt-header">
            <h2 class="excerpt-title">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </h2>
        </div>
        <div class="excerpt-content">
            <article>
                <?php ct_tracks_excerpt(); ?>
            </article>
        </div>
    </div>
</a>

Resulting in this HTML

<div class="post-45 post type-post status-publish format-standard has-post-thumbnail hentry category-ui excerpt zoom full-without-featured odd excerpt-1">
    <a class="featured-image-link" href="http://kamerondesigns.dev/post-4/">
        <div class="featured-image lazy" data-background="http://kamerondesigns.dev/wp-content/uploads/sandwich-1024x614.jpg" style="background-image: url(&quot;http://kamerondesigns.dev/wp-content/uploads/sandwich-1024x614.jpg&quot;);"></div>
    </a>
</div>
<a href="#">
</a>
<div class="excerpt-container">
    <a href="#">
    </a>
    <div class="excerpt-meta">
        <a href="#">
            <span class="category">
    </span>
        </a><a href="http://kamerondesigns.dev/category/ui/">UI</a> </div>
    <div class="excerpt-header">
        <h2 class="excerpt-title">
                <a href="http://kamerondesigns.dev/post-4/">Post 4</a>
            </h2>
    </div>
    <div class="excerpt-content">
        <article>
        </article>
    </div>
</div>

Read more here: PHP within anchor’s divs causing undesired output

Leave a Reply

Your email address will not be published. Required fields are marked *