Using WordPress ‘permalink_link()’ PHP function

The permalink_link() WordPress PHP function prints the permalink of the current post in the loop.

Usage

permalink_link();

Parameters

  • None

More information

See WordPress Developer Resources: permalink_link

Examples

Display the permalink in a post loop

This example will display the permalink of each post while looping through them.

if (have_posts()) :
    while (have_posts()) : the_post();
        echo 'Post permalink: ';
        **permalink_link()**;
        echo '<br />';
    endwhile;
endif;

This example adds the permalink to a “Read more” link for each post in the loop.

if (have_posts()) :
    while (have_posts()) : the_post();
        the_excerpt();
        echo '<a href="';
        **permalink_link()**;
        echo '">Read more</a><br />';
    endwhile;
endif;

Display post title with permalink

This example shows how to display the post title with its permalink.

if (have_posts()) :
    while (have_posts()) : the_post();
        echo '<a href="';
        **permalink_link()**;
        echo '">';
        the_title();
        echo '</a><br />';
    endwhile;
endif;

This example adds the permalink to a custom-styled “Read more” button for each post in the loop.

if (have_posts()) :
    while (have_posts()) : the_post();
        the_excerpt();
        echo '<a class="read-more-button" href="';
        **permalink_link()**;
        echo '">Read more</a><br />';
    endwhile;
endif;

Display post thumbnail with permalink

This example shows how to display the post thumbnail with its permalink.

if (have_posts()) :
    while (have_posts()) : the_post();
        echo '<a href="';
        **permalink_link()**;
        echo '">';
        the_post_thumbnail();
        echo '</a><br />';
    endwhile;
endif;