# Although WordPress fully supports Markdown via the JetPack plugin and Markdown supports code blocks there are occasions where the encoding gets thrown off on posting and has to be edited before making a post live.

Chris Aldrich linked to a piece on the WordPress.com support pages that details the [code] shortcode which, with a language parameter, preserves formatting and even adds syntax highlighting within posts and pages.

This is native to WordPress.com but a plugin is available for self-hosted blogs which I may start using.

Compare the two blocks below:

function make_post($post){
    $post = [
        'title' => $title,
        'content' => $body,
        'status' => $status,
        'format' => $format,
    return $post;

[code lang="php"] function make_post($post){ $post = [ 'title' => $title, 'content' => $body, 'status' => $status, 'format' => $format, ]; return $post; } [/code]

The first is the standard Markdown rendering (I had to correct the greater than symbols having been converted to >) and the second uses the plugin.

Pretty cool!

In Drafts I can create an action that inserts the shortcode after prompting for the language I want and I'll look at creating an Alfred workflow to do the same thing.

(You’ll need to visit the actual post to see the difference as you won’t get the effect via RSS.)

6 comments: click to readComments

# I'm starting to build a little library of Alfred workflows from around the web. Nothing amazing but just a few little things to make life easier such as:

  • mark all as read in mail.app
  • take screenshots (because I can never remember the keyboard shortcuts)
  • toggle do not disturb
  • look up synonyms and antonyms (and paste the selected word)
  • open things like specific folders or my WordPress dashboard

I'm still not very familiar with AppleScript (I've learnt how to do a few things) but that will come with time.

# I've also now created a Drafts action and Alfred workflow to insert the [code] shortcode with the specified language type into whatever I'm writing. Just like the actual WordPress.com shortcode, if no language is entered they default to txt.

Drafts prompts me for the language (php, js, etc.) whereas with Alfred I type the language as part of the command - code php for example.

Colin Walker Colin Walker colin@colinwalker.blog