Danny Brown

A Blog on Code and Occasionally Other Things

Using Code Prettify and CSS to Highlight Code on WordPress

Danny BrownDecember 17, 2018

I’ve moved my blog to a new host that lets me use the full features of WordPress. The first implementation of this is the Code Prettify plugin. Once you’ve installed the plugin to your WordPress site, it adds some quick and easy syntax highlighting to tagged code.

In-line code looks like this: print "Hello, world!". Just use the <code>Your Code Here</code> tags.

Code blocks look like this:

for item in items: 
    print item

For these, use the <pre> tags like this:

<pre>

Your Code Here:
    With White Space Respected

</pre>

Both of these tags will give you some nice monospaced font and some subtle syntax highlighting. I wanted my code to stand out a little bit more, so I used WordPress’s customization options to add a background property. After selecting the Customize menu on WP, I went to the last option, Additional CSS.

Then I added some simple CSS style, which shows off what I want:

code, pre {
  background: #EEEEEE;
}

It’s that easy! This added the light gray background that you can see above and here:
print("Thanks for reading!")

Posted In code | CSS | Python

Post navigation

PreviousSavannah Stopover with a Kid: A Parent’s Guide and Review
NextCollecting Merge Field Names from Multiple Word Documents Using Python

Danny Brown

A Dev Blog with Some Tangents

About

Categories

  • code
    • APIs
    • Bash
    • CSS
    • Django
    • HTML
    • JavaScript
    • Python
    • S3
    • Selenium
    • Serverless
    • TypeScript
  • games
  • music
    • concert reviews
    • synthesizers
  • opinion
  • sports
  • tech
    • Bitbucket
    • Git
    • GitHub
    • MS Teams
    • WordPress
  • theater

Recent Posts

  • Open Pull Requests from the Terminal (One of My Favorite Dotfiles Scripts)
  • Dotfiles Script for a New TypeScript/Node Project
  • So I Told You to Go See a Broadway Play? Tips for Theater in New York
  • Build a Simple Microsoft Teams Bot Easily, No SDK Required
  • Creating a GUI for Conway’s Game of Life Using Pygame and Numpy

External Links

  • GitHub
  • LinkedIn

Recent Posts

  • Open Pull Requests from the Terminal (One of My Favorite Dotfiles Scripts)
  • Dotfiles Script for a New TypeScript/Node Project
  • So I Told You to Go See a Broadway Play? Tips for Theater in New York
  • Build a Simple Microsoft Teams Bot Easily, No SDK Required
  • Creating a GUI for Conway’s Game of Life Using Pygame and Numpy

Categories

  • code
    • APIs
    • Bash
    • CSS
    • Django
    • HTML
    • JavaScript
    • Python
    • S3
    • Selenium
    • Serverless
    • TypeScript
  • games
  • music
    • concert reviews
    • synthesizers
  • opinion
  • sports
  • tech
    • Bitbucket
    • Git
    • GitHub
    • MS Teams
    • WordPress
  • theater
Copyright © 2025. Danny Brown
Powered By WordPress and Meritorious