钩子文档

post_thumbnail_url

💡 云策文档标注

概述

post_thumbnail_url 是一个 WordPress 过滤器钩子,用于修改或过滤文章缩略图的 URL。它允许开发者在获取缩略图 URL 时进行自定义处理。

关键要点

  • 过滤器名称:post_thumbnail_url
  • 参数:$thumbnail_url(缩略图 URL 或 false)、$post(文章 ID 或 WP_Post 对象)、$size(图像尺寸)
  • 用途:在 get_the_post_thumbnail_url() 函数中调用,用于动态调整缩略图 URL
  • 版本:从 WordPress 5.9.0 开始引入

代码示例

apply_filters( 'post_thumbnail_url', $thumbnail_url, $post, $size );

📄 原文内容

Filters the post thumbnail URL.

Parameters

$thumbnail_urlstring|false
Post thumbnail URL or false if the post does not exist.
$postint|WP_Post|null
Post ID or WP_Post object. Default is global $post.
$sizestring|int[]
Registered image size to retrieve the source for or a flat array of height and width dimensions. Default 'post-thumbnail'.

Source

return apply_filters( 'post_thumbnail_url', $thumbnail_url, $post, $size );

Changelog

Version Description
5.9.0 Introduced.