0

I've built a site up over a few years (3,500+ posts) where I've inserted images using the traditional method into the post content itself.

I'm now moving to a different theme, and have made the first image for each post the featured image (which I want to keep), but I now would like to remove the first image from the_content.

I have found that I can remove the first image (with or without captions) on the fly by instead of using the_content(), doing this:

echo preg_replace("/\[caption .+?\[\/caption\]|\< *[img][^\>]*[.]*\>/i","",get_the_content(),1);

Is there some way I can run this command on the database to actually remove those images?

Thanks for any pointers

  • Has this been actually tested? The regex doesn't look right to me - what are you trying to match with "[img]" or "[.]*"? – user27457 Apr 6 '14 at 3:42
  • Export your database tables to your desktop.than you can remove all unwanted tags by using any text editor such as notepad++.do not forget getting back up.after this,remove all tables which site use than import sql file to database. – ahmetlutfu Apr 6 '14 at 8:55
  • @MagentaCuda Yes, the code seems to work on my setup, but obviously it's rather database intensive to do this for every post shown on a medium-sized website. Here's the source of that code btw - wordpress.org/support/topic/… – Tim Apr 6 '14 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.