How I can remove all internal or external links on my posts at once? just remove link and leave anchor text.


Not sure about the database but you can do it easily with the_content filter, just add the code below to your current (child) theme functions.php file:

add_filter( 'the_content', 'misha_remove_all_a' );
function misha_remove_all_a( $content ){

    return preg_replace('#<a.*?>(.*?)</a>#is', '\1', $content);

  • 1
    Obligatory Comment: avoid manipulating HTML with regexps. That one will break on <a title="and>">. Just because you wouldn't doesn't mean others won't write wonky stuff in their documents. – janh Oct 14 '17 at 17:29
  • Agreed. I also trying to avoid such stuff, but sometimes you may need fast and easy solution. – Misha Rudrastyh Oct 14 '17 at 17:42
  • Totally, I'm guilty of that as well. But you have to try to warn those that haven't yet stepped onto this dangerous path ;) – janh Oct 14 '17 at 17:47
  • I with an option here to add likes to comments :) – Misha Rudrastyh Oct 14 '17 at 17:48
  • thanks, but will not remove it from db, this is just a temporary solution. – techno Oct 14 '17 at 20:15

Target your links with some CSS. In default twentyseventeen theme it's

.entry-content a {
   pointer-events: none;
   cursor: default;
add_filter('the_content', 'removelink_content',1);

function removelink_content($content = '')
    preg_match_all("#<a(.*?)>(.*?)</a>#i",$content, $matches);
    $num = count($matches[0]);for($i = 0;$i < $num;$i++){
        $content = str_replace($matches[0][$i] , $matches[2][$i] , $content);
    return $content;

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.