钩子文档

get_sample_permalink

💡 云策文档标注

概述

get_sample_permalink 是一个 WordPress 过滤器,用于修改或自定义文章示例固定链接的生成。它允许开发者在返回示例链接时介入处理,基于文章属性如 ID、标题、名称和文章对象进行调整。

关键要点

  • 过滤器名称:get_sample_permalink
  • 参数:$permalink(包含占位符的链接数组)、$post_id(文章 ID)、$title(文章标题)、$name(文章名称/slug)、$post(WP_Post 对象)
  • 用途:过滤示例固定链接,常用于自定义链接结构或基于文章属性动态生成链接
  • 相关函数:get_sample_permalink(),位于 wp-admin/includes/post.php
  • 引入版本:4.4.0

代码示例

apply_filters( 'get_sample_permalink', $permalink, $post->ID, $title, $name, $post );

📄 原文内容

Filters the sample permalink.

Parameters

$permalinkarray
Array containing the sample permalink with placeholder for the post name, and the post name.

  • 0 string
    The permalink with placeholder for the post name.
  • 1 string
    The post name.

$post_idint
Post ID.
$titlestring
Post title.
$namestring
Post name (slug).
$postWP_Post
Post object.

Source

return apply_filters( 'get_sample_permalink', $permalink, $post->ID, $title, $name, $post );

Changelog

Version Description
4.4.0 Introduced.