2

So, my cousin owns a fashion blog and she recently had a fall out with a brand of shoes and she wants to remove all the links on all posts that point to the brand website.

So, is there a way I can automatically via SQL commands or maybe a plugin check all posts on the blog and turn links like this:

<p style="text-align: center;"><a href="http://specific-url.com/prod1">Awesome Product 1</a></p>

Into just text without links:

<p style="text-align: center;">Awesome Product 1</p>

The ideia is basically to find all links starting with http://specific-url.com/ and remove the <a>tag.

Thank you.

4

You can use the Search Regex plugin. This will allow you to create a regular expression to intelligently search and replace across all of your posts.

After you activate the plugin, go to Tools, Search Regex. If you want to remove all links to http://example.com, here is one regular expression you could try:

/<a href="http:\/\/example\.com[^>]*>([\s\S]*?)<\/a>/

Enter that into the "Search pattern" box, and enter $1 into the "Replace pattern" box. Choose "Post content" for the Source, and check the "Regex" checkbox. Then click the "Replace" button. This won't change anything in your database (yet), but it will show you a preview list of all the changes that it will make. To actually make the changes, click the "Replace & Save" button. Or if you see from the preview that your regular expression is matching something you don't want it to, then change your regular expression and try again.

With a bulk edit like this, it's probably a good idea to back up your database before you begin, just in case you make a mistake.

Screenshot:

enter image description here

  • 1
    Whenever you have a difficult search problem, think regex: xkcd.com/208 – Ben Miller - Reinstate Monica Oct 22 '13 at 11:14
  • Thank you, this really helped me, here's an extended version of your regex in case someone wants to replace both http and https (with and without www) plus multiple domains: /<a href="(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)(example\.com|example\.org|example\.net)[^>]*>([\s\S]*?)<\/a>/. In that case the replace pattern field should become $3 instead of $1. The http/https portion is taken from this snippet - regextester.com/93652 . Also need to mention that my regex knowledge is pretty basic, so this might have bugs or it could be further improved. – Sledge Hammer Feb 27 at 16:32
3

There is no plugin to remove anchor tags with that url ( atleast I don't know any ), but you can replace the url with this plugin

http://wordpress.org/plugins/search-and-replace/

Plugin

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.