While working on my post about sharing maven version rules I had trouble getting the syntax highlighting to work correctly. By accident, I stumbled upon the solution.

While writing my post, I inserted SyntaxHighlighter code blocks with the plaintext source code, expecting them to be nicely formatted, syntax highlighted and everything upon publishing.

screenshot of a piece of a blog post in visual editor mode with a sytnaxhighlighter block showing xml code

Unfortunately, no matter what I tried, during publishing/previewing the code example got screwed up (the right angle brackets got replaced by HTML-entities and the highlighting no longer worked):

screenshot of a published blog post using a syntaxhighlighter code block showing xml where the right angle brackets have been replaced by their HTML-entities, resulting in broken code examples and the highlighting not working.

I am currently on WordPress version 5.1.1 and using the SyntaxHighlighter-Evolved plugin version 3.5.0 . I looked around for a solution but could find none. There was some hints about using shortcodes around the pasted code (for example, [xml]code here[/xml]) but that only made things worse.

The SyntaxHighlighter-Evolved plugin I’m using is untested for WordPress versions above 5.0.4, which might have been the cause of my problems. This worried me because the author of this plugin has recently passed away and there seems to be no clear successor at this time, let alone an upcoming update.

Then, while playing around with it again the next day it suddenly worked!

screenshot of a published blog post with a syntaxhighlighter code block showing proper xml (including right angle brackets) with proper syntax highlighting.

Elated, I continued working on my post, switching back from my admin user (which I had logged into to check the plugin’s details) to my “normal” user.
And it broke again immediately.

After some experimenting, I found out that it only works correctly if I use an account with the role “Editor” or “Admin”. Roles of “Author” and below don’t work for some reason, probably some kind of permissions problem. So now my “plain author” user is using the role of “Editor” which is not that bad (better than “Admin” for sure) and everything works as expected.

I have opened an issue on the plugin’s github repository in the hopes of helping others with the same problem.

Leave a Reply

Your email address will not be published. Required fields are marked *