最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

media - wp_get_attachment_image_src() returns wrong url

programmeradmin3浏览0评论

wp_get_attachment_image_src() is returning a wrong image url. It returns the original url instead of the cropped one. Here some example code:

    $ptId = get_post_thumbnail_id( $productId );
    print_r(wp_get_attachment_image_src( $ptId, 'thumbnail'));
    print_r(wp_get_attachment_image_src( $ptId, 'medium'));
    print_r(wp_get_attachment_image_src( $ptId, 'medium_large'));

Returns:

Array ( [0] => //localhost:3000/.../wp-content/uploads/2020/06/Mineral-Lipstick-Crème-Brûlée-scaled-1.jpg [1] => 100 [2] => 150 [3] => ) 
Array ( [0] => //localhost:3000/.../wp-content/uploads/2020/06/Mineral-Lipstick-Crème-Brûlée-scaled-1.jpg [1] => 200 [2] => 300 [3] => ) 
Array ( [0] => //localhost:3000/.../wp-content/uploads/2020/06/Mineral-Lipstick-Crème-Brûlée-scaled-1.jpg [1] => 768 [2] => 1152 [3] => )

The image sizes do exist and you can see that the function 'kind of' detects them. I've also regenerated them (both with wp-cli & the regenerate thumbnails plugin) just to be on the sure side but alas.

I don't quite get it, I've been using this function for years and suddenly I'm not getting the desired results. Any idea as to what might be going wrong?

发布评论

评论列表(0)

  1. 暂无评论