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.

The full code for the loop in case it's helpful: https://jsfiddle.net/hemjegzy/

Any help is greatly appreciated.

Loop Code (Trimmed)

        if ( have_posts() ) :
        while ( have_posts() ) : the_post();
    <article id="post-<?php the_ID(); ?>" <?php post_class( 'post-single-no-sidebar' ); ?>>

        <?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>' );
            <a href="<?php get_permalink(); ?>">
                <?php the_post_thumbnail(); ?>


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.

1 Answer 1


get_permalink doesn't output anything, it returns the permalink. Your first call works because you use it within the_title, which echos its value along with any before and after parameters you pass to it.

Change your second instance to:

<?php echo get_permalink(); ?>

or use the_permalink, which echos the value instead of returning.

<?php the_permalink(); ?>

Many functions within WordPress follow this same pattern, get_ vs. the_, one returns for use within php, one prints to page.

  • I thought it would be something simple, thank you. May 24, 2017 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.