1) For existing post content, you can add a filter to the_content
to remove them from the output before they are seen by a user:
function remove_tag_links( $content ) {
return preg_replace( '#<a [^>]*\bhref=\\\?"[^"]+(?=/tag/)[^"]+\\\?"[^>]*>(.+?)</a>#si', '$1', $content );
}
add_filter( 'the_content', 'remove_tag_links' );
2) For new / updating content, you can add the same filter to content_save_pre
to take the links out before they are saved to the database:
add_filter( 'content_save_pre', 'remove_tag_links' );
Note that my pattern expects double-quotes (and possibly backslashed-escaped double quotes, for content_save_pre
) around the href attribute value, and can handle other attributes within the tag.
The filter I provided simply removes the link markup, but leaves behind the text. If you want to remove the entire tag including its text, pass an empty string ''
instead of '$1'
as the second parameter to preg_replace