preg_match() not working with post content
In your code, $content does not exist. You need to accept the argument into your function: function find_my_image( $content ) { if ( is_single() ) { if ( preg_match( ‘/(<img[^>]+>)/i’, $content, $result ) ) { $content .= ‘<p>Image has been found</p>’; } else { $content .= ‘<p>Sorry, no image here!</p>’; } } return $content; } … Read more