Regex - Remove anchor tags wrapped around img tags
I'm currently working on a very large WordPress build that is heavily populated with posts. I've had a request come through where I have to do the following...
Remove all anchor tags that are wrapped around img tags.
For example, I need the following...
<a href="some-random-page"><img src="some-radom-image"/></a>
To become...
<img src="some-random-image"/>
Could this at all be done using an SQL update statement that I can run in phpMyAdmin as all WordPress posts are stored in the "posts" table.
Hope someone can help.
Solutions
You can do so with Dreamweaver. Export your
db table
. Open in Dreamweaver.
Find the following with "regular expression" option checked.
<a href="([^>]*)"><img src="([^>]*)"/></a>
Now replace this with:
<img src=$2/>
Now import the
db table
back to MySQL.
For match use :
(<a[^<]*>.*?)(<img[^>]*>)([^<]*</a>)
For replace use :
$2
Example : http://RegExr.com?37vbk
(replace dummy text in the example with your string)
Similar questions
anchor wrapped li for Slide-out menu in wordpress
i'm trying to do something like this: http://cssdeck.com/labs/3fo47n21 in wordpress, but i'm having trouble to get the navigation to wrap menu li with anchor tags like this: All i got is this in the header: You guys are my last resort, any advice?
Adding link tags and rel="lightbox" around images Regex
How can i change this example when i just got the <image> tag and i want to add link tags around them and the rel lightbox attribute as well? i cant figure it out. I'm just not good with regular expressions at all. the example So in my case i have <img src="...." class="...." alt="....."> and i need <a href="....." rel="lightbox" tit...
removing <p> tags around img, iframes and also scripts
I've been working with embeded content and as many already know, wordpress wraps the_content() lines in p tags. So, found this: When I change "iframe" by "script" it works, but then only for one of them, I need both beacuse the twitter embbeds create a hidden script element wich in turn creates a ghost paragraph.
remove anchor element around Wordpress images with filter (or jquery)
I have an anchor element like this: (It's the standard way of Wordpress to embed uploaded pictures in a post.) I want to remove the anchor around the image element, but keep the image. I simply want the image to show without being clickable. This could be done either with a filter for the content of a post in Wordpress or after the page is loaded w...
Also ask