Markdown in WordPress – and writing blog posts is fun again
As you may have noticed, I hadn’t blogged here for quite a while, but have recently started blogging regularly again. This is mostly due to sorting out various WordPress issues I was having, and installing some new plugins to make writing blog posts fun again.
Ever since I installed the WordPress update that added the ‘Gutenberg’ editor, I had various problems with editing and creating new posts. I eventually switched back to the Classic Editor (following these instructions), but still wasn’t really happy. I’ve never really been a huge fan of the WordPress editor – it has been a fiddly to get things formatted the way I want, and it’s never dealt with code snippets very well.
I’ve had some plugins installed to do syntax highlighting, but these have required typing the code into a separate little dialog, and not being able to edit it easily after adding it. I really wanted to be able to include code as easily as I do in Markdown documents using ‘code fence’ syntax. For example, something like this:
(with no spaces between the backticks – I had to include those or that example would have been syntax highlighted for me)
Basically, I wanted to write my posts in Markdown. I investigated static blog generators, but didn’t want to deal with converting all of my previous posts, and trying to make sure URLs still redirected properly and so on.
Anyway, I found a solution which works really well for me: the WP Githuber MD plugin.
This allows you to write your posts in Markdown, and it supports Github-style fenced code blocks, with syntax highlighting.
All you need to do is install it and then enable the correct settings. To do this:
- Go to the Plugins -> Installed Plugins page
- Find ‘WP Githuber MD’ and click ‘Settings’
- Go to the ‘Modules’ tab at the top
- Turn the switch on the right-hand side of the ‘Syntax Highlight’ heading on
- Fiddle with the syntax highlighting settings to your own preferences
- (Optional) Turn on the switch next to ‘Image Paste’ to make it really easy to add images to your posts
That’s all that needs doing – now your code blocks will be nicely formatted, and you don’t have to bother with typing code into silly dialogs, just write the post in Markdown and insert code as usual and everything ‘just works’.
As a brief postscript, the ‘Image Paste’ functionality is also really useful. Simply copy an image from somewhere on your computer – often I’m copying something like a matplotlib graph produced by a Python script – and then switch to the Markdown editor and paste. The image will then be uploaded to your WordPress Media Library and the right code to include the image will be inserted. All done with a single keypress!
So yes, overall, I am a big fan of WP Githuber MD – I’ve not been asked to say this, but it has really transformed my blog editing experience!