Second get_permalink inside loop points to wrong URL

For some reason the second get_permalink located on the featured image is pointing to the current page, instead of the post URL.

The first get_permalink works fine. They are both inside the same loop.

I’ve posted a trimmed down version of the loop below. Didn’t want to remove all non-essentials or may remove the cause of the problem.

The full code for the loop in case it’s helpful:

Any help is greatly appreciated.

Loop Code (Trimmed)

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <article id="post-<?php the_ID(); ?>">
    <!-- Post Header -->    
        <?php if ( is_single() ) { ?>           
            the_title( '<h1 class="entry-title">', '</h1>' );
            } else {
                the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' );
    <!-- / Post Header -->  

    <!-- post content -->
        <div class="featured-image">
          <a href="<?php get_permalink() ;?>">
                <?php the_post_thumbnail(); ?>
     <!-- / Post Content -->


Additional notes:

All plugins and versions of WordPress are up-to-date. I have checked any plugins may be the cause of the issue.

I’ve looked at answer to:

WP get_permalink Return Wrong URL

Custom post type’s get_permalink returns wrong url

Login to wp-admin “redirect_to” points to wrong URL after migration

I do not believe these are the same issues.

Read more here: Second get_permalink inside loop points to wrong URL

Leave a Reply

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