Remove specified site URLs from content

I have a WordPress blog and several authors. I want to remove some of the website urls from my blog content. For example, I don't want ANY myspace urls in the post content, not just myspace.com

than myspace.com/whatever

or myspace.com/faq.html

.

Is it possible to do this with some php code or adding some code to the file .htaccess

?

Thanks.

0


a source to share


1 answer


.htaccess can't help you here.

You should be able to put together a fairly simple plugin, something like this:

add_filter('the_content', 'myspace_url_filter', 999);

function myspace_url_filter($content) {
  return preg_replace('/(<a[^>]href=["'])[^"']+myspace.com[^"']+["']/', '\1#"', $content);
}

      



Note that this is far from a perfect regular expression; it can be avoided by replacing the myspace domain name with the myspace IP (luck with keeping track of all the public IPs they use ...), common XSS techniques, using any url redirection service like tinyURL (to catch this, d watch out for every link and any redirects) or just link to a page that contains the corresponding link (like the tinyURL preview page).

In short, any technical countermeasure you can think of can be easily defeated, and even the simplest workarounds can take extremely difficult work on your part.

It may be easier to just talk to your contributors, make your wishes clear, and discipline any author who refuses to obey your no myspace links rule.

+4


a source







All Articles