On my WordPress page I sometimes have the issues, that WordPress puts
tags around elements, where I don't want them. For instance, I have this "invisible anchor" on many pages:
<a class="anchor" id="some-id"></a>
WordPress puts a
tag around it, which inserts a space, where I don't want one.
I know I can filter the content with something like this:
function filter_ptags($content) {
return preg_replace('/<p(.)*(anchor)(.)*<\/p>/', '<a class="anchor"></a>', $content);
}
add_filter('the_content', 'filter_ptags');
However, the problem with this is, that the anchor has an individual ID of course, which I don't know. How can I solve this?
preg_replace( '/\<a class=["|\'|]anchor["|\'|] id=["|\'|].+["|\'|]\>(.*)?\<\/a\> ?/si', '', $content );
can filter it away, but you need to SSH into your server and find which plugin/file is triggering that bygrep -Rn '<a class="anchor"'
or downloading the site locally and searching with a text editor such as Sublime Text. – Samuel Elh Sep 16 '17 at 20:58