Blogging with org2blog

This post you’re seeing is the first one posted using org2blog. Finally, I can blog from Emacs, yay!

Frankly I’m not too fussy with my blog setup: any decent website will do as long as I can type text in, format stuffs, and the final page is readable. My previous blog was on, which I had to abandon because the login system was screwed up for many months, preventing me from even logging in, much less posting comments or new entries.

My current blog, the site you’re reading now hosted by WordPress, is not too bad. But there are two problems I’m having: first, the in-browser editor is limited and sometimes has annoying couple-of-second freezes every now and then. And second, the worse one, is that I’ve noticed the text changed at least twice. A few months ago I saw my Perl source code inside <pre> got HTML-escaped, so “$a > $b” becomes “$a &gt; $b”. This does not happen to all posts, only some of them. But I’m just too lazy to check my posts one by one. And more recently, suddenly all my “pericmd-tut” (with a lowercase i) tags became “perlcmd-tut” (with a lowercase ell), as if someone had run an autocorrect on the tags database. I updated a few dozen posts this time, reverting the tags back to “pericmd-tut” and meanwhile starting to ponder for alternatives.

Today I decide to give org2blog a try. I’ve heard about this tool like a couple of weeks ago and yesterday I had an idea for a blog post. Here are the general steps and some examples if you happen to be interested to follow suit.


The first thing I had to do was put the *.el from the org2blog package under my $HOME/.emacs.d directory as M-x install-package didn’t work out for me. ($HOME/.emacs.d/lisp should be a better choice, but I haven’t bothered to move my *.el files there.) I also had to drop xml-rpc.el and metaweblog.el from into this same directory. Those two are the requirements mentioned in the org2blog README.

Then I appended these lines to my $HOME/.emacs:

(require 'org2blog-autoloads)
(setq org2blog/wp-blog-alist
         :url ""
         :username "<censored>"
         :password "<censored>"
         :default-title "Post"
         :default-categories ("perl")
         :tags-as-categories nil)
(setq org2blog/wp-use-sourcecode-shortcode t)

I guess the README doesn’t recommend putting the password right there along with the username, but for simplicity sake I just put it anyway.

Also note that you can use an existing blog (as in my case). org2blog can add new posts or delete existing ones based on post ID’s which you supply later.

Then I restarted my Emacs.

Creating a new post

Each post is put in a separate buffer (file).

To create a new post, M-x org2blog/wp-new-entry. org2blog will create a new buffer containing something like this:

#+DATE: [2016-05-03 Tue 14:47]
#+OPTIONS: toc:nil num:nil todo:nil pri:nil tags:nil ^:nil
#+CATEGORY: perl
#+TITLE: Post

You can then edit the title, tags, or categories. And start writing. You can save the buffer anywhere as regular files. This post itself is saved as an .org file then put under a Git repository.

Posting to WordPress

To post the buffer as draft, M-x org2blog/wp-post-buffer (or C-c M-p d). And to publish the buffer C-u M-x org2blog/wp-post-buffer (or C-c M-p p). org2blog will also ask you whether you want to open the post in a browser to see how the final result looks like.

That’s it, it’s that simple. Now you can write in the cozy and powerful Emacs environment, and your source document is in Org format instead of the default bastardized HTML that WordPress uses.

After the first sending to the server, org2blog will add a #+POST_ID: line containing the post’s ID. If you edit the buffer, then re-post, it will update the existing post since the buffer already specifies the post’s ID. Editing your blog posts is now as simple as editing a file with an extra single command to push it to WordPress.

Some formatting examples

To see the Org source code that produces these result, see the abovementioned Git repository.

This is a Perl code block:


use strict;
use warnings;
use Org::Parser;

my $orgp = Org::Parser->new;
my $doc = $orgp->parse_file("$ENV{HOME}/");

This is another Perl code block, which we set to begin from line 75 and have its lines 77-78 highlighted:

my @elems = $doc->select("Table:first TableCell:empty");
for my $elem (@elems) {
    $log->trace("Deleting empty element %s", $elem);

7 thoughts on “Blogging with org2blog

  1. Pingback: [Reading] “Blogging with org2blog” | perspicazsite

  2. Pingback: Emacs and Org-Mode – Molten Steel

  3. Pingback: Diminishing returns – HamitySpace

  4. Pingback: Hello World – Yours Blog

  5. Pingback: How to create a new blog post through org2blog – Yours Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s