Let’s give it a try:
$str="<img src="http://myserver.mydomain/picture.png" />";
$pattern ='#<img src="http://.*/(.*)" />#';
$replace="<img src="http://http://i0.wp.com/$1?quality=70&strip=all />"";
$result = preg_replace($pattern, $replace, $str);
The $pattern is quite simple and very specific. You might need to generalize it a bit more but it should show you the direction to go. E.g. it takes no care of possible whitespace. A first attempt to take care of this:
$pattern ='#<\s*img\s*src\s*=\s*"http://myserver.mydomain/(.*)"\s*/\s*>#';
Related Posts:
- Removing any and all inline styles from the_content()
- how to display post content without post image?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- How do I display main query posts in random order using add_filter
- How to exclude native lazy loading from first image in post content?
- Rewrite image links from attachment id to attachment link
- Prevent WordPress from putting around specific element
- Add review box by function at top or bottom of content
- Assign custom class to post content images
- the_content() not displaying the full post
- How to allow visitors to filter posts by multiple taxonomies
- Show only posts with images and a fixed amount of posts
- Issue where WP Featured Image will not display
- How would one change the default url structure of attachments?
- Filter only the text in the_content
- Redirect to another page using contact form 7? [closed]
- Trying to alter the post_content through the_post
- If statement to check if post has image
- Gather posts into a cart/lightbox and share with another user
- How to check if single.php has already called the_post_thumbnail function
- add to end of post in the loop with plugin
- Thumbnail Image to go in the post aswell
- Add filter to the end of the post
- Remove Featured Image & All Media Uploaded to the Post
- Get post content with all filters applied, knowing post id
- Adding bootstrap classes to video shortcodes
- Is it possible to filter the main loop to exclude posts from a specific category?
- What are the benefits of setting a “featured image” for a WP blog post?
- query post limits
- preg_replace not removed “class”
- update image path with words starting uppercase to lowercase chars
- How to disable the_excerpt from one post
- How to only publish posts with image in it
- Modify posts listing at back end
- Uploading images in custom post form
- Filtering posts on Post Administration Page by Week Number instead of by Month
- Upload attachment from external site
- Make insterted image point to post url instead of attachment page
- Prevent posts with certain post_meta to be edited
- Get URL from all images in a post
- Change the default blog post post attribute template name from “default template” to something else
- Disable posts generated from image uploads
- Hook for changing excerpt content when excerpt not set
- Is it possible to add a shortcode below post title?
- how to give multiple post thumbnails to a post
- Post filtering is returning blank page
- Posts page not showing correct image
- Images showing up in Post Editor, but not in Published Post
- How to allow multiple thumbnail upload for Posts?
- Image behind the post’s title
- get_children returns older images
- How to display post title inside thumbnail?
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- How include css class based on post ( in loop ) slug?
- Add div before the first paragraph the_content [closed]
- How to remove text and retain in caption image using the_content function
- How to retrieve certain number of images from a wordpress post?
- the_content() Not Grabbing All Content
- Restrict displaying posts to the poster itself (in Back-end)
- How to filter url on post submission?
- Show more than 200 images in one post
- How to get all inline images in post content? [duplicate]
- Hide thumbnail if there is a gallery on the post
- Exists filter or action that change Add New Post link?
- Image on rss feed on post
- Change the background of each post according to the category
- How to Featured content with images in home page?
- Where to insert the other site image url for our wordpress post
- select post preview image from nextgen gallery
- How to show a featured image inside a post in only 1 single category
- Inserting Media to WordPress Posts
- Author Avatar as default first image
- Link post images to post
- How to get the next and previous image title from attachment or gallery?
- Attachment image single page
- How to change the order of elements within a post?
- Only show featured image on exerpt and exclude images in post
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- changing parent_id on post
- How to call WordPress First Image Post or else Attached Image or Default
- wp_list_categories() Exclude All Categories Except One
- Regarding Posts
- Adding if statement into the_content()
- how can display a post on home screen without images
- Get current taxonomy and display query accordingly
- Trying to exclude custom posts based on date, while sorting by custom field
- Changing The Default Header POST Title and Description text by category in wordpress
- can’t modify post title using the_posts filter
- why my urdu text is not aligned properly when written in wordpress blog post?
- Show only posts with titles/permalinks that do not contain certain words
- Site/Post preview is not working on all social media
- user_has_cap filter allows “edit_others_posts” but not is not allowing updating/publishing
- Delete media from the post but keep my featured image and post
- Using AJAX to filter posts without refreshing page
- Aligning images in the wp editor not working. How do i get this to work in custom theme?
- Filter posts by month (dropdown)
- unable to write to the database while uploading images
- Restricting displayed posts to posts from only select authors
- How to get title of images in post content
- How to limit wordpress the_excerpt() dynamically