WordPress plugin for blogging code to preserve formatting and not run the code

This is not a blog about coding but from time to time it may be that I want to show code in the body of a post without it losing its formatting and removing the code I am trying to show.

I know it is possible so I had a look around for plugins. I tried out several, and there are even more that I could have tried, but I stopped when I got to one that basically did what I want. One thing to note is that if you are including code, do not write your post in the visual editor as it will mess things up.

It also seems worthwhile to me to have a page on this blog that lists the plugins that I have installed – and maybe that is good practice anyway as a safety net for backup. If you need to transfer everything to a new server or your blog gets corrupted, backing up the content will keep your prompt list to remind you what to reinstall to get things back to how they were. If you don’t want the world to know such things you can always make the page private or just not include it in any menus.

The plugin I am using is WP Code Highlight. You only need to enclose the code in the pre tag, and I picked it because it has a CSS file with several options for formatting the code separately, which you can pick in the settings link on the Installed Plugins page of the Dashboard. I’m using the wp-code-highlight option on the Highlight Themes with Line Numbers enabled and it is demonstrated below. However I should say while this was the best I have found so far it is still not so pretty. The sons-of-obsidan theme has a black background and shows up the text well, but I don’t want a black background. The sunburst theme lost some text white on white so that is no good. The desert theme was too light. This one the rows are not ideal – perhaps it is conflicting with something in the overall background theme of the blog? But you can see all of the code and it has preserved the layout.




    jQuery UI Lesson

    
    
    

	
	
	
	
	

	
	



	


Drag me around
Resize me
Drop here

You may also like...

Leave a Reply