Adding automatic code highlighting to your blog

This article was published 4 years ago. Due to the rapidly evolving world of technology, some concepts may no longer be applicable.

Update: PrismJS is a much better option now

One of the things I really liked about wp-svbtle is that it would automatically highlight any code samples I added. When I changed to Sparkling, the highlighting stopped.

Thankfully, it was an easy fix. To re-enable it, I added the following to my footer.php file in the theme:

<script>
jQuery("pre code").addClass("prettyprint");
</script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

This enables all code blocks to be pretty printed, then includes Google’s pretty printer library. As you can see, it works like a dream.

Thoughts on this post

Leave a comment?

Leave a Reply