Wordpress expert ! Help required!

Discussion in 'WordPress' started by mike4uuu, Apr 22, 2011.

  1. #1
    How can i remove all the attachment link ("www.mysite.com/?attachment_id=xxx") from all the images in all the post !

    I can remove it by editing one by one but since i have more than 500 post , its killing me and my fingers !

    I'm sure there must be an easy way to do this ! i tried using a few plugin like search and replace / replace /search regen but its not solving my issue !

    Will be great if an expert here can guide me on this issue !
    Thanks in advance !

    Regards
     
    mike4uuu, Apr 22, 2011 IP
  2. Mr.AD

    Mr.AD Member

    Messages:
    89
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    41
    #2
    You can export your dabase to sql file, use a text editor to find and replace them. After that, re-import it.
     
    Mr.AD, Apr 22, 2011 IP
  3. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    its difficult since the format is different in html code !

    I want to remove the bold parts from all my posts! Is there any other way to solve this issue !
     
    mike4uuu, Apr 22, 2011 IP
  4. carsandchicks

    carsandchicks Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can use a filter to remove the links before the content is displayed. You can find more on filters in the Wordpress Codex: codex.wordpress.org/Plugin_API/Filter_Reference/the_content The filter would be something like preg_replace("/link-code/", "", $content);
     
    carsandchicks, Apr 22, 2011 IP
  5. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #5
    can you please guide me ! elaborate more in using the filters! how can i use this filters
     
    mike4uuu, Apr 22, 2011 IP
  6. Mr.AD

    Mr.AD Member

    Messages:
    89
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    41
    #6
    You must know PHP and understand WordPress structure for they way @car said.
     
    Mr.AD, Apr 22, 2011 IP
  7. Mr.AD

    Mr.AD Member

    Messages:
    89
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    41
    #7
    You must know PHP and understand WordPress structure for they way @car said.
     
    Mr.AD, Apr 22, 2011 IP
  8. carsandchicks

    carsandchicks Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    In your functions.php file in the theme you are using you have to add a function which will filter the post content. In should be something like this:

    
    function remove_a_tags($content) {
        $pattern = "/<a rel=\"(.*?)><img(.*?)<\/a>/ig";
        $replacement = "<img$2";
        $content=preg_replace($pattern, $replacement, $content);
        return $content;
    }
    
    add_filter( "the_content", "remove_a_tags" );
    
    PHP:
    But you have to figure the regular expression yourself - mine is just an example, which I haven't tested. It most probably won't work as it is and needs tweaking.
     
    carsandchicks, Apr 23, 2011 IP
  9. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #9
    i have installed a wp plugin which does the above same function! the only problem i m facing is , i m not able to get the right expression for search and replace !
    search = "<a rel=\"(.*?)><img(.*?)<\/a>"
    replace = "<img$2"
     
    mike4uuu, Apr 24, 2011 IP
  10. carsandchicks

    carsandchicks Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The expression I gave earlier works, you just need to remove the 'g' modifier, e.g.:
    Please note that this will work only if the plugin you found uses regular expressions and not plain search&replace (str_replace). If you still can't make it to work, give me the name of the plugin and an example post content and I will try to find the problem.
     
    carsandchicks, Apr 24, 2011 IP