函数文档

get_the_permalink()

💡 云策文档标注

概述

get_the_permalink() 是 WordPress 中用于获取文章或页面完整固定链接的函数,它是 get_permalink() 的别名,适用于开发者快速获取当前或指定文章的 URL。

关键要点

  • 函数是 get_permalink() 的别名,功能完全一致
  • 接受两个可选参数:$post(文章 ID 或对象,默认全局 $post)和 $leavename(是否保留文章名称占位符,默认 false)
  • 返回字符串类型的固定链接 URL,若文章不存在则返回 false

代码示例

get_the_permalink( $post_id, false );
// 返回包含文章 slug 的 URL,例如:"https://example.com/2025/01/my-post-title/"

get_the_permalink( $post_id, true );
// 返回包含通用文章占位符的 URL:"https://example.com/2025/01/%postname%/"

📄 原文内容

Retrieves the full permalink for the current post or post ID.

Description

This function is an alias for get_permalink() .

See also

Parameters

$postint|WP_Postoptional
Post ID or post object. Default is the global $post.
$leavenamebooloptional
Whether to keep post name or page name.

Default:false

Return

string|false The permalink URL. False if the post does not exist.

Source

function get_the_permalink( $post = 0, $leavename = false ) {
	return get_permalink( $post, $leavename );
}

Changelog

Version Description
3.9.0 Introduced.

User Contributed Notes