WordPress at a glance

the_permalink() WP 1.2.0

Displays link (URL) to the post that is currently being processed in the Loop.

This template tag can be used only inside the Loop of WordPress.

  • Since 4.4.0 Added the $post parameter.
Works based on: get_permalink()
✈ 1 time = 0.002275s = very slow | 50000 times = 5.62s = fast PHP 7.1.2, WP 4.7.3
Hooks from function:
Return

Nothing (null).

Usage

the_permalink( $post );
$post(int/WP_Post)
Post ID or post object.
Default: global $post

Examples

#1 Let's display a link to the post in the form of simple text, not html link

Address of this post: <?php the_permalink(); ?>

#2 Let's display html link to the current post

The link text will be: "permanent link":

<a href="<?php the_permalink(); ?>">permanent link</a>

#3 Display a link to the current post

The text of the link will be the title of the post.

This is the standard way to output a link to a post within a Loop:

<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>

Code of the_permalink: wp-includes/link-template.php VER 4.9.8

<?php
function the_permalink( $post = 0 ) {
	/**
	 * Filters the display of the permalink for the current post.
	 *
	 * @since 1.5.0
	 * @since 4.4.0 Added the `$post` parameter.
	 *
	 * @param string      $permalink The permalink for the current post.
	 * @param int|WP_Post $post      Post ID, WP_Post object, or 0. Default 0.
	 */
	echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) );
}

Related Functions

From tag: permalinks (clean friendly URL)

More from tag: WP Loop

More from category: Posts, pages...

More from Template Tags: Links (URL)

No comments
    Hello, !     Log In . Register