gpt4 book ai didi

wordpress - 将自定义类添加到 "wp_get_attachment_image( $attachment_id)"wordpress 函数

转载 作者:行者123 更新时间:2023-12-04 11:18:39 25 4
gpt4 key购买 nike

我可以使用 wp_get_attachment_image($attachment_id) wordpress 函数获取图像。它会自动添加以下代码。

<img width="150" height="150" src="http://localhost/test2/wordpress/wp-content/uploads/2019/08/pexels-photo-1308624-150x150.jpeg" class="attachment-thumbnail size-thumbnail" alt="">

我想使用这个函数添加“alt”和另一个类。具体来说,我想生成这样的代码。
<img width="150" height="150" src="http://localhost/test2/wordpress/wp-content/uploads/2019/08/pexels-photo-1308624-150x150.jpeg" class="attachment-thumbnail size-thumbnail custom-class" alt="Some Alt Value">

最佳答案

你可以这样通过它。

<?php echo wp_get_attachment_image( $attachment_id, 'thumbnail', "", ["class" => "my-custom-class","alt"=>"some"]); ?>

您可以在此处阅读完整的文档。
https://developer.wordpress.org/reference/functions/wp_get_attachment_image/

关于wordpress - 将自定义类添加到 "wp_get_attachment_image( $attachment_id)"wordpress 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57307751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com