How to create a regular expression for when a link contains wp-content/uploads
path? The problem is somewhere in this wp-content/uploads
part.
You can see an example here https://regexr.com/3ro5n
(<a.*? href=".+?(?:\/wp-content\/uploads)+")><img
In the end I am trying to add a class to this links for Lightbox, if those links contain an image
function give_linked_images_class($content) {
$classes = 'fancybox';
if ( preg_match('/<a.*?><img/', $content) ) {
$content = preg_replace('/(<a.*? href=".+?(?:\/wp-content\/uploads)+")><img/', '$1 class="' . $classes . '" ><img', $content);
}
return $content;
}
add_filter('the_content','give_linked_images_class');