我可以使用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">
答案 0 :(得分:2)
您可以这样传递它。
<?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/
答案 1 :(得分:0)
您可以传递多个属性,对于您可以执行的自定义类:
<?php echo wp_get_attachment_image($image_id, 'full', false, array('class' => 'my-custom-class')); ?>