post_thumbnail_size
云策文档标注
概述
post_thumbnail_size 是一个 WordPress 过滤器钩子,用于修改文章缩略图的尺寸。它允许开发者动态调整缩略图的大小,支持注册的图像尺寸名称或像素数组。
关键要点
- 过滤器名称:post_thumbnail_size
- 参数:$size(字符串或整数数组,指定图像尺寸),$post_id(整数,文章 ID)
- 用途:在 get_the_post_thumbnail() 等函数中过滤缩略图尺寸
- 版本历史:从 2.9.0 引入,4.9.0 添加了 $post_id 参数
代码示例
$size = apply_filters( 'post_thumbnail_size', $size, $post->ID );注意事项
- $size 参数可以是已注册的图像尺寸名称(如 'thumbnail')或包含宽度和高度的像素数组(例如 [800, 600])
- 使用此过滤器时,确保正确处理 $post_id 参数以针对特定文章调整尺寸
原文内容
Filters the post thumbnail size.
Parameters
$sizestring|int[]-
Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
$post_idint-
The post ID.
Source
$size = apply_filters( 'post_thumbnail_size', $size, $post->ID );