钩子文档

post_thumbnail_id

💡 云策文档标注

概述

本文档介绍了 WordPress 中的 post_thumbnail_id 过滤器,用于修改或过滤文章缩略图的 ID。该过滤器允许开发者在获取缩略图 ID 时进行自定义处理。

关键要点

  • post_thumbnail_id 是一个过滤器,用于过滤文章缩略图的 ID。
  • 参数包括 $thumbnail_id(缩略图 ID 或 false)和 $post(文章 ID 或 WP_Post 对象)。
  • 该过滤器在 WordPress 5.9.0 版本中引入。

代码示例

return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id, $post );

注意事项

  • 如果文章不存在,$thumbnail_id 参数可能为 false。
  • 默认情况下,$post 参数使用全局 $post 对象。
  • 相关函数包括 get_post_thumbnail_id(),用于检索文章缩略图 ID。

📄 原文内容

Filters the post thumbnail ID.

Parameters

$thumbnail_idint|false
Post thumbnail ID or false if the post does not exist.
$postint|WP_Post|null
Post ID or WP_Post object. Default is global $post.

Source

return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id, $post );

Changelog

Version Description
5.9.0 Introduced.