How to publish post to WordPress with Org2Blog in Emacs

1. Initialize your environment

Download and install these dependencies: xml-rpc, metaweblog, org2blog, htmlize. The dependencies are available in Melpa and Github
In this post, I use Melpa

M-x package-install RET xml-rpc
M-x package-install RET metaweblog
M-x package-install RET org2blog
M-x package-install RET htmlize

Now, you must define what packages you’re going to use in ‘.emacs’ or ‘init.el’

(require 'xml-rpc)
(require 'org2blog-autoloads)
(require 'netrc)

And then you must key in your username and password in a file by creating’.netrc’.
The content of the file like this:

machine your-name-blog login your-user-name password your-password


machine myblog login noname00 password 12345

After finished the profile, turn back to your init emacs file.
Now add these code for your init file.

;; This is for define location where your account file is.
;; I've referenced it to the emacs location for easily manage.
(setq your-name-blog (netrc-machine (netrc-parse "~/.emacs.d/.netrc") "your-name-blog" t))

;; Setting your Blog configuration.
(setq org2blog/wp-blog-alist
         :url ""
         :username ,(netrc-get your-name-blog "login")
         :password ,(netrc-get your-name-blog "password")
         :default-title "Hello World"
         :default-categories ("emacs")
         :tags-as-categories nil)))

Note: if your WordPress or any blog need https please add “https” prefix in the url.

Note: There are differences between ‘ and ` so you had better use as the template.

Note: When you switching to https, your emacs need install “gnutls” for SSL Security encryption purpose. So you need to download here and then extract to your location of Emacs example C:\Program Files\Emacs\
Link: Download here

Finally, you add these code for finishing the boring things.

;; implemented as HTML styling. Your pick!
(setq org2blog/wp-use-sourcecode-shortcode 't)

;; removed light="true"
(setq org2blog/wp-sourcecode-default-params nil)

;; target language needs to be in here
(setq org2blog/wp-sourcecode-langs
      '("actionscript3" "bash" "coldfusion" "cpp" "csharp" "css" "delphi"
        "erlang" "fsharp" "diff" "groovy" "html" "javascript" "java" "javafx" "matlab"
        "objc" "perl" "php" "text" "powershell" "python" "ruby" "scala" "sql"
        "vb" "xml"
        "sh" "emacs-lisp" "lisp" "lua"))

(setq org-src-fontify-natively t)

;; You want set the keymode map you can use these.
(global-set-key (kbd "<f1> l") 'org2blog/wp-login)
(global-set-key (kbd "<f1> p") 'org2blog/wp-post-buffer-and-publish)

2. Create a post and publish

After restarting your Emacs, and make sure there’s no error in “warning” buffer. Now these step is very easy, you just create a ‘.org’ file, and follow example structure.

"#+TITLE: Your_Name_Title_Post"
"#+CATEGORY: Your_catergory"
"#+DESCRIPTION: Describe something on here."

"* My heading here"
"** Small heading"
What you want to write it's now here
For adding the shortcode please add the tag 
"#+BEGIN_SRC" "your_language_here"


Adding a picture:

Please remove “” and \, when typing in org mode, otherwise it will not work.

Finally, you’ve to login into your Blog by typing: “f1-l” and post “f1-p”. Auto Update Post: After posting completely, The post id will exist in your *.org file, save it. Whenever you want to update your post, just typing: “f1-p” It will auto update your post.

3. Install syntax plugin for wordpress

You need to install syntax plugin in order to display format code.

Leave a Reply

Your email address will not be published. Required fields are marked *