WordPress TinyMCE removes anchor tags if they wrap block elements when switching from text to visual

I was able to disable this behavior in backend with this code:

function override_mce_options($initArray)
{
    $opts = '*[*]';
    $initArray['valid_elements'] = $opts;
    $initArray['extended_valid_elements'] = $opts;
    $initArray['valid_children'] = '+a[*]';
    return $initArray;
}

add_filter('tiny_mce_before_init', 'override_mce_options');

It works if I paste this into the editor:

Read More
<a href="#" class="text-center text-info"><h5 class="title">Heading</h5></a>

and press update button without switching to visual mode. But when pasting and switching to visual mode the editor removes the anchor tag and leaves h5 alone. I know some js is messing up with this but I have no idea what file is responsible for this and how to prevent this behavior.

Related posts

Leave a Reply

1 comment

  1. I found a solution that works perfectly. I just installed “Preserved HTML Editor Markup Plus” plugin and it solved all the issues I had with TinyMCE messing up with my html markup.