Removing links from posts in wordpress

3 replies
  • WEB DESIGN
  • |
Hi,
I have few blogs for some clients. I need to remove links to one of my clients in all posts. Just to be clear i need to remove links and my keyword should stay like it is.
I found this plugin.
But this one remove all links.
I need to remove all links just for one client, and links for other clients should stay unchanged.
Does anyone know about some good plugin for this solution?
Is there any way using SQL statements? I need solution to recognize link no meter what is keyword and to remove href text leaving keyword unchanged.
Thanks in advance!
#links #posts #removing #sql #wordpress
  • Profile picture of the author Nathan K
    Here is a simple function i have written that can hide the links you want.

    Paste the following code in your functions.php file and add the websites url (without the www) to the $list array.

    function remove_specific_links_from_post($post){
    $list = array(
    'bing.com',
    'google.com'
    );
    foreach($list as &$value)
    $post = preg_replace('/<a href=\"http(s)?:\/\/(www\.)?'.$value.'\">(.*?)<\/a>/i', "\\3", $post);
    return $post;
    }
    add_filter('the_content', 'remove_specific_links_from_post')
    {{ DiscussionBoard.errors[8530611].message }}
    • Profile picture of the author MarkoOS
      Hi,
      Thanks a lot for reply.
      This solution look very nice. But i test it on the simplest theme Twenty ten. I added code in function.php and add in list 'linktoremove.com' and nothing is happening. My links linktoremove.com are still there?
      {{ DiscussionBoard.errors[8604909].message }}
  • Profile picture of the author Nathan K
    Links are not removed from the original post. When you view the post in the front end, it removes the anchor tags. And its working fine in twentytwelve and twentythirteen theme.
    {{ DiscussionBoard.errors[8606136].message }}

Trending Topics