【问题标题】:Wordpress, filter/action before image renders?Wordpress,图像渲染之前的过滤器/操作?
【发布时间】:2021-11-29 15:37:46
【问题描述】:

我的任务是在图像上渲染水印,所以我必须复制图像并在图像上渲染水印。问题是,如何从前端管理它?例如,我想使用 wp_get_attachment_image_src() 函数,并且过滤器可能会更改源文件 URL。怎么做? 这一定有效:wp_get_attachment_url 但后来我不知道附件的 ID,所以我无法制作缩略图

【问题讨论】:

    标签: wordpress filter action attachment


    【解决方案1】:

    试试这个过滤器

    apply_filters( 'wp_get_attachment_image_src', array|false $image, int $attachment_id, string|int[] $size, bool $icon )

    function alter_image_src($image, $attachment_id, $size, $icon)
    {        
        $image[0] = 'http://example.com/test.jpg';
    
        return $image;
    }
    add_filter('wp_get_attachment_image_src', 'alter_image_src', 10, 4);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-01
      • 2017-06-26
      • 2018-01-27
      • 1970-01-01
      • 2016-03-14
      相关资源
      最近更新 更多