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.

Возвращает

Null. Ничего.

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 the function

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>

Список изменений

С версии 1.2.0 Введена.
С версии 4.4.0 Added the $post parameter.

Code of the_permalink() WP 5.5.1

wp-includes/link-template.php
<?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
    Log In . Register