Embed pictures in WordPress comments

WordPress seventy-six 6.6K Reading mode

Sometimes you need to add pictures to make comments, but WordPress itself does not have the function of comment mapping. You can add the following code to the current theme functions.php file:

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

After adding the above code, you can paste the image link address directly when posting a comment.

The specific effect can be posted in this article.

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
Comments seventy-six    Visitors seventy-three    Author three
    •  Orange book
      Orange book one

      It seems that the function of posting pictures in comments is not used much.

      •  Win7en Paradise
        Win7en Paradise seven

        Can I upload it? Brother Bird, I want to upload pictures on your website and use them to make a drawing bed. :cool:

          •  wechat Business
            wechat Business four

            @ Win7en Paradise Paste the address directly, and the image will be displayed, which cannot be uploaded

            •  Sporty bicycle
              Sporty bicycle seven

              @ Win7en Paradise  :eek: Your idea is really ingenious. It's really high!

                •  Xiao Wu
                  Xiao Wu one

                  @ Sporty bicycle Hello, blogger, I use your method to add an image address and submit a comment. After the page is refreshed or reopened, the image will become an address, and the image will not be displayed. When I check the source code, I find that there is no img tag, and it is directly "image address", which will definitely not be displayed. I want to ask why this occurs? Everything was fine when I submitted it..

              •  Yaxi
                Yaxi four

                This is more personalized, which makes the comments more vivid. In order to save space, we can only use the external chain pictures

                •  wechat Business
                  wechat Business four

                  I forbid picture comments

                  •  BanYuner
                    BanYuner five

                    This is a good choice. I have another idea. Thanks for the inspiration from the robin blog

                    •  Inspirational Quotes
                      Inspirational Quotes six

                      Sofa, like one

                      •  Uncle Louis
                        Uncle Louis six

                        Embedded pictures seem interesting

                        •  Sporty bicycle
                          Sporty bicycle seven

                          I like this feature :wink:

                          •  Test picture
                            Test picture zero

                            Test picture
                            http://ww4.sinaimg.cn/large/703be3b1jw1faji7snd0oj20kk0as0u4.jpg

                            •  desert
                              desert zero

                              How to add target='_blank 'attribute to all links in the article content??? I also found some code on the Internet, but it doesn't work under the begin theme. I would like to invite Brother Bird to give me a tutorial on the relevant articles.

                                •  Robin
                                  Robin

                                  @ desert If you are my theme user, you can directly Q me

                                •  The blog of Mingyue climbing the stairs
                                  The blog of Mingyue climbing the stairs five

                                  Let me test it!
                                  http://zmingcx.com/wp-content/uploads/2016/11/Begin-a.png

                                  •  wechat Business
                                    wechat Business four

                                    Test it and see if it works well

                                    •  The blog of Mingyue climbing the stairs
                                      The blog of Mingyue climbing the stairs five

                                      Hey hey, it seems that the size of the picture has been enlarged! It affects the beauty very much! It would be perfect if you could click zoom!

                                      •  Win7en Paradise
                                        Win7en Paradise seven

                                        Don't say anything, try pasting a picture! Recently, I found a Japanese copyright free portrait website, which is still very good. https://www.pakutaso.com/assets_c/2016/04/akanesayapp-thumb-1500 ×736-21700.jpg

                                        •  Win7en Paradise
                                          Win7en Paradise seven

                                          Ha ha, it's really beautiful. I will go to this website to find articles and pictures in the future. It's really beautiful! https://www.pakutaso.com/shared/img/thumb/GSAYA_IMG_4626_TP_V.jpg

                                          •  Win7en Paradise
                                            Win7en Paradise seven

                                            I don't know how the vertical picture works. Let me test it for Brother Bird! Get up! https://www.pakutaso.com/assets_c/2016/09/AKANE20160312232713-thumb-autox1600-26192.jpg

                                            •  meirizhi
                                              meirizhi one

                                              When there are many pictures, it is better to use CDN acceleration.
                                              Refer to www.meirizhi.com

                                              •  Meiya Meitie
                                                Meiya Meitie one

                                                The mobile terminal automatically matches the template, asking the blogger to publish an article that prohibits mobile terminal transcoding

                                                •  The light of some cat
                                                  The light of some cat one

                                                  Let me feel it
                                                  http://ww3.sinaimg.cn/large/703be3b1jw1f9h5zion3fj20kk0bxdij.jpg

                                                  •  Long Xiaotian
                                                    Long Xiaotian five

                                                    Feel the beauty~ :mrgreen:
                                                    http://lxtx.qiniudn.com/hanxue-Cecilia_wm950.jpg

                                                    •  OK?
                                                      OK? three

                                                      Let me see

                                                      •  OK?
                                                        OK? three

                                                        Why not?

                                                        •  Ding Chunhua
                                                          Ding Chunhua two

                                                          Let me try the texture, https://down.dingchunhua.name/wp-content/uploads/2016/12/douyaohaohaode.jpg

                                                          This is the original picture. Some pictures are big and some pictures are small, so the whole comment area is occupied by the picture without unified specifications. You still need to unify the style of the picture, Brother Bird :oops:

                                                          •  Inaction
                                                            Inaction three

                                                            Can you make a WordPress mobile login? This mobile comment doesn't need to be logged in. Just fill in these information. What if you set the article login visible? Mobile users can't log in. They need to make a new button for mobile login

                                                            •  Inaction
                                                              Inaction three

                                                              Can you customize the WordPress mobile template,

                                                              •  sir
                                                                sir zero

                                                                pretty good

                                                                •  achieve
                                                                  achieve zero

                                                                  Test
                                                                  http://zmingcx.com/wp-content/uploads/2016/11/beginb.png

                                                                  •  Inaction
                                                                    Inaction three

                                                                    http://ww3.sinaimg.cn/mw690/d83cce73gw1fag3s8aj2xj206y04n74e.jpg Test comments

                                                                    •  I want to earn money online
                                                                      I want to earn money online two

                                                                      I got confused when I saw the code

                                                                      •  The blog of Mingyue climbing the stairs
                                                                        The blog of Mingyue climbing the stairs five

                                                                        This link does not support Sina Chart Bed! There seems to be no extension behind the links of Sina Chart Bed! Depressed!

                                                                        •  Technology box
                                                                          Technology box two

                                                                          Could you tell me how to make comments show pictures in the sidebar?

                                                                          •  two billion two hundred and seventy-seven million nine hundred and fifty-one thousand nine hundred and seventy-five
                                                                            two billion two hundred and seventy-seven million nine hundred and fifty-one thousand nine hundred and seventy-five two

                                                                            Learn~~~~~~~~~~~~~~~~~··

                                                                            •  Yang Yong
                                                                              Yang Yong two

                                                                              121 Learn

                                                                                •  source
                                                                                  source one

                                                                                  @ Yang Yong pretty good

                                                                                  •  source
                                                                                    source one

                                                                                    @ Yang Yong Good gvgfgghhhh

                                                                                  •  Zh°U
                                                                                    Zh°U zero

                                                                                    Support Support

                                                                                    •  Let me try
                                                                                      Let me try zero

                                                                                      Try to see if the text will interfere http://imgs.zmingcx.com/wp-content/uploads/2016/11/Begin-a.png have a try

                                                                                      •  Test picture
                                                                                        Test picture zero

                                                                                        http://ww3.sinaimg.cn/mw690/d83cce73gw1fag3s8aj2xj206y04n74e.jpg
                                                                                        Test picture

                                                                                        •  have a try
                                                                                          have a try zero

                                                                                          picture http://wx3.sinaimg.cn/mw690/8c1483d3gy1fgyjn917fqj20xc1e0tv5.jpg

                                                                                          •  walt
                                                                                            walt zero

                                                                                            Picture test
                                                                                            https://b-ssl.duitang.com/uploads/item/201709/23/20170923172432_VWrzY.jpeg

                                                                                              •  Test it
                                                                                                Test it two

                                                                                                @ walt fail

                                                                                              •  gghgg
                                                                                                gghgg two

                                                                                                I want to see this theme

                                                                                                •  More stuff
                                                                                                  More stuff zero

                                                                                                  https://cn.gravatar.com/avatar/0e0b5f76dd70c7e02a6525bf11b292c8?s=96&r=g&default=http%3A%2F%2Fzmingcx.com%2Fwp -content%2Fthemes%2Fbegin%2Fimg%2Favatar%2F96%2Flatin_z.png
                                                                                                  Easter months after gale

                                                                                                  •  Xigu Blog
                                                                                                    Xigu Blog one

                                                                                                    Xigu blog test https://0d077ef9e74d8.cdn.sohucs.com/qKlNj0W_png

                                                                                                    •  Wordpress enterprise theme
                                                                                                      Wordpress enterprise theme zero

                                                                                                      How to add a field to upload images directly

                                                                                                      •  Ha ha ha
                                                                                                        Ha ha ha zero

                                                                                                        Ha ha ha ha ha ha https://cdn.dwhnews.com.cn/wp-content/themes/begin/img/random/64.jpg

                                                                                                        •  one hundred and twenty-three
                                                                                                          one hundred and twenty-three zero

                                                                                                          have a look

                                                                                                          •  Bean husk
                                                                                                            Bean husk zero

                                                                                                            Boring picture
                                                                                                            http://wx4.sinaimg.cn/mw600/bd03f0e8gy1fvdt46qe1lj20hs0go0uj.jpg

                                                                                                            •  ha-ha
                                                                                                              ha-ha three

                                                                                                              test https://ss0.baidu.com/73x1bjeh1BF3odCf/it/u=488620432 ,3347708386&fm=85&s=C284BC0D196EDF1F8D74BCDA0300C0B4

                                                                                                              •  Taizhuang Information
                                                                                                                Taizhuang Information five

                                                                                                                Brother Bird, can you upload a picture on Weibo :oops:

                                                                                                                •  bend one's head ↘ Kiss you
                                                                                                                  bend one's head Kiss you one

                                                                                                                  http://zmingcx.com/wp-content/themes/begin/thumbnail.php?src=http://wx3.sinaimg.cn/large/0066LGKLly1fzgdnmh78rj30xc0d6q7s.jpg&w=280&h=210&a=&zc=1 Three gods

                                                                                                                  •  bend one's head ↘ Kiss you
                                                                                                                    bend one's head Kiss you one

                                                                                                                    http://wx4.sinaimg.cn/large/0066LGKLly1fx2xdr5y6zj308r0670to.jpg :idea:  :neutral:  :neutral:  :neutral: See the effect

                                                                                                                    •  s6bnnn
                                                                                                                      s6bnnn zero

                                                                                                                      http://zmingcx.com/wp-content/themes/begin/thumbnail.php?src=https://wx4.sinaimg.cn/large/0066LGKLly1g0kmdrak58j31040i5gmn.jpg Ha ha ha

                                                                                                                      •  Geek retro
                                                                                                                        Geek retro zero

                                                                                                                        https://www.51dry.cn/wp-content/uploads/2018/02/cropped-logo.png
                                                                                                                        Try commenting with pictures.

                                                                                                                       anonymous

                                                                                                                      Comment

                                                                                                                      Anonymous netizens
                                                                                                                       :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

                                                                                                                      Drag the slider to complete validation