我认为问题在于,您试图获取图像的元数据,而没有指定宽度和高度的大小。
$imgData = wp_get_attachment_metadata( get_post_thumbnail_id( get_the_ID() ) );
$width = $imgData[\'width\'];
$height = $imgData[\'height\'];
相反,请尝试以下操作:
$imgID = get_post_thumbnail_id( get_the_ID() );
$imgURL = wp_get_attachment_image_src( $imgID, \'full\' ); // now I know which image specifically I want - in this case \'full\'.
$width = $imgURL[\'1\']; // I\'ve never tested \'height\' and \'width\', but 100% the array numbers work
$height = $imgURL[\'2\'];
现在我知道了我正在测试的特定img url的高度和宽度。