如何在每个 WordPress 帖子图片周围添加一个 Div? [英] How do I add A Div around each WordPress post image ?

查看:33
本文介绍了如何在每个 WordPress 帖子图片周围添加一个 Div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 wordpress 博客文章中发布的每个图像周围添加一个 div.我该怎么做?

I want to add a div around every image that is posted on my wordpress blog post. How can I do it?

(对于好奇的人,我试图在用户将鼠标悬停在图像上时弹出一些共享按钮).

(For the curious ones, I'm attempting to pop out some share buttons whenever a user hovers over an image).

推荐答案

将以下代码片段添加到您的 functions.php 文件中:

Add the following snippet of code into your functions.php file:

add_filter( 'image_send_to_editor', 'wp_image_wrap_init', 10, 8 );    
    function wp_image_wrap_init( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
    return '<div id="wp-image-wrap-'. $id .'" class="wp-image-wrap">'. $html .'</div>';
}

这篇关于如何在每个 WordPress 帖子图片周围添加一个 Div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆