Home > CMS Tutorial > WordPress > body text

How to embed images in WordPress comments

藏色散人
Release: 2019-12-02 14:28:23
forward
2304 people have browsed it

下面由WordPress建站教程栏目给大家介绍WordPress 评论中嵌入图片的方法,希望对需要的朋友有所帮助!

How to embed images in WordPress comments

有时发表评论需要添加图片,而WordPress本身并不具备评论贴图功能,可以将下面的代码添加到当前主题functions.php文件中:

add_action('comment_text', 'comments_embed_img', 2);
function comments_embed_img($comment) {
    $size = auto;
    $comment = preg_replace(array(&#39;#(http://([^\s]*)\.(jpg|gif|png|JPG|GIF|PNG))#&#39;,&#39;#(https://([^\s]*)\.(jpg|gif|png|JPG|GIF|PNG))#&#39;),&#39;<img src="$1" alt="评论" style="width:&#39;.$size.&#39;; height:&#39;.$size.&#39;" />&#39;, $comment);
    return $comment;
}
Copy after login

添加上述代码后,在发表评论时直接粘贴图片链接地址即可。

具体效果可以在本文留言并贴图。

The above is the detailed content of How to embed images in WordPress comments. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!