我可以得到图片使用wp_get_attachment_image($attachment_id) wordpress function.It自动添加以下代码。
<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">发布于 2019-08-01 19:27:35
你可以像这样传递它。
<?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/
发布于 2021-06-16 17:13:28
您可以传递多个属性,对于自定义类,您可以这样做:
<?php echo wp_get_attachment_image($image_id, 'full', false, array('class' => 'my-custom-class')); ?>https://stackoverflow.com/questions/57307751
复制相似问题