post_permalink()
云策文档标注
概述
post_permalink() 是一个已弃用的 WordPress 函数,用于根据文章 ID 或 WP_Post 对象检索固定链接。自 4.4.0 版本起,建议使用 get_permalink() 替代。
关键要点
- 函数 post_permalink() 已弃用,自 WordPress 4.4.0 起应改用 get_permalink()。
- 参数 $post 可选,可以是整数(文章 ID)或 WP_Post 对象,默认为全局 $post。
- 返回值是字符串(固定链接)或 false(如果检索失败)。
- 函数内部调用 _deprecated_function() 标记弃用,并重定向到 get_permalink()。
代码示例
function post_permalink( $post = 0 ) {
_deprecated_function( __FUNCTION__, '4.4.0', 'get_permalink()' );
return get_permalink( $post );
}注意事项
- 在开发新代码时,避免使用 post_permalink(),直接使用 get_permalink() 以确保兼容性。
- 如果维护旧代码,建议逐步替换 post_permalink() 调用为 get_permalink()。
原文内容
Retrieve permalink from post ID.
Description
See also
Parameters
Source
function post_permalink( $post = 0 ) {
_deprecated_function( __FUNCTION__, '4.4.0', 'get_permalink()' );
return get_permalink( $post );
}
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Deprecated. Use get_permalink() |
| 1.0.0 | Introduced. |
Skip to note 2 content
Codex
Usage