1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Anyone know of a way to search and replace links in a blog

Discussion in 'Black Hat SEO' started by theindiaphile, Jan 27, 2012.

  1. theindiaphile

    theindiaphile Senior Member

    Joined:
    Jul 26, 2010
    Messages:
    830
    Likes Received:
    245
    I have an old WP blog that was abused by a content network to the point where i had to remove it. It's full of about 4000 spam type links within content which I would now like to replace with links of my choice. However, the search and replace plugin I've found is unable to handle replacing html code. Would really appreciate a solution if anyone knows one...?
     
  2. wickedguy

    wickedguy Supreme Member

    Joined:
    Jul 22, 2009
    Messages:
    1,402
    Likes Received:
    1,379
    Location:
    BHW--> South Africa
    Home Page:
    Here's a quick and dirty plugin I created for you. Feel free to make changes as you desire. :D
    PHP:
    <?php
    /*
    Plugin Name: Strip Links :)
    Plugin URI: http://wpsynit.zar.vg
    Description: Strip Links from content
    Version: 1.0
    Author: wickedguy
    Author URI: http://wpsynit.zar.vg
    */


    add_filter('the_content''strip_links'2);

    function 
    strip_links($content){

    $mylink='http://yourownlink.com';
    $mykeyword='yourownkeyword';

    $pattern='/<a(.*?)<\/a>/si';
    preg_match_all($pattern,$content,$matches);
    for (
    $i=0$icount($matches[0]); $i++) {
    $content str_replace($matches[0][$i],"<a href='$mylink'>$mykeyword</a>" ,$content);
    }

    return 
    $content;
    }

    ?>
     
    • Thanks Thanks x 3
  3. theindiaphile

    theindiaphile Senior Member

    Joined:
    Jul 26, 2010
    Messages:
    830
    Likes Received:
    245
    Damn, you just made that. You are a LEGEND! Rep given!!!
     
  4. popzzz

    popzzz Supreme Member

    Joined:
    Apr 12, 2009
    Messages:
    1,337
    Likes Received:
    13,699
    Location:
    Don't touch the REP!

    You said you had to remove it - if you have it on windows just use one of the many
    find/replace utilities available like in notetab, notepad++, etc.

    You might want to do that anyway just for convenience.

    Enjoy ..... :cool2: