pre_get_shortlink
云策文档标注
概述
pre_get_shortlink 是一个 WordPress 过滤器,用于在生成短链接前进行干预,允许开发者自定义或阻止短链接的生成过程。
关键要点
- 过滤器名称:pre_get_shortlink
- 作用:返回非 false 值将短路短链接生成,直接返回该值
- 参数:$return(false 或 URL 字符串)、$id(文章 ID)、$context(上下文,如 'post' 或 'query')、$allow_slugs(是否允许文章别名)
- 应用场景:在 wp_get_shortlink() 函数中调用,用于控制短链接输出
- 版本历史:自 WordPress 3.0.0 引入
代码示例
$shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs );
原文内容
Filters whether to preempt generating a shortlink for the given post.
Description
Returning a value other than false from the filter will short-circuit the shortlink generation process, returning that value instead.
Parameters
$returnfalse|string-
Short-circuit return value. Either false or a URL string.
$idint-
Post ID, or 0 for the current post.
$contextstring-
The context for the link. One of
'post'or'query', $allow_slugsbool-
Whether to allow post slugs in the shortlink.
Source
$shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs );
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |