Remove all links in post content

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

Topic posts Wordpress

Category Web


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;
}

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);

}

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

.entry-content a {
   pointer-events: none;
   cursor: default;
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.