需要在wordpress条件php中检测帖子/页面内容中图像的链接

I'm building a theme on wordpress, and I need a conditional if the post or page content has links to images (href = "....../fubar.jpg").

This would:

if (is_singular () && ** conditional true to content with links to pictures **) {
/ / This post/page has links to images 
else {} 
/ / No link to image found 
}

Would have to detect jpg, png and gif.

Is it possible to do this in wordpress?

Yes, Wordpress is a php framework and in php you can detect that.

What you could do, is use an xml parser like DOMDocument or Simple HTML DOM Parser to see if there are any links and process them if you find them. You could do that by opening the link and checking the file type (or process it as an image with for example getimagesize() and check the result).

Apparently you can use get_the_content() to return the content, then a library like simple html dom to find out if it has images:

if(str_get_html(get_the_content())->find('img', 0)){
  // there's an image
} else {
  // there's not an image
}