Blogging with Emacs and WordPress
Tags: writing, emacs, misc
Published: 2020-03-11 03:17:36

---
title: Blogging with Emacs and WordPress
published: true
date: 2020-03-08 04:40:00 UTC
tags: Writing,Emacs,misc
canonical_url: https://coderscat.com/blogging-with-emacs-and-wordpress
---

![2019_10_26_emacs-with-wordpress.org_20200308_224524.png](https://coderscat.com/wp-content/uploads/2019_10_26_emacs-with-wordpress.org_20200308_224524.png)

## Hexo and Jekyll are good, but…

I write about programming, technology, and other topics.

10 years ago, I started blogging with WordPress and then transferred to Jekyll several years later, then continually moved to Hexo.

Jekyll and Hexo are fascinating tools for programmers to generate content files into the HTML page. We only need to publish generated results onto a server.

The generated pages are minimized and super fast. We can use Git or any other version control tools to manage posts.

In one word, with these tools we can blog like coding, it’s the style of programmers.

## Blogging with Emacs and WordPress

I begin this new blog recently, for practicing another style of writing: writing for others.

However, I realized recently, WordPress is still a good choice for technical blogging.

WordPress is the most popular tools for building a site, it’s more than 20 years old and with many existing good plugins.

## Org2Blog is amazing

I have used org-mode for about 2 years. I won’t change to write on the dashboard of WordPress. [Org2Blog](https://github.com/org2blog/org2blog) is the reason I want to use Emacs for blogging. The experience of writing in org-mode is amazing.

The whole workflow is:

1. Use `org-capture` to create a new file of org-mode
2. Edit the post
3. Use the command `org2blog/wp-post-buffer-and-publish` to commit the post to WordPress.

## Some handy configurations

This is my `org=capture-templates`. All posts are stored in the directory: `~/Dropbox/org/blog/`, images are stored in a subdirectory of `imgs`.

```
(defun create-org-file-with-dir (dir)
  (lexical-let ((dir dir))
  (lambda ()
    (interactive)
    (let ((name (concat (format-time-string "%Y_%m_%d_")
                        (read-string "file-name: "))))
      (expand-file-name (format "%s.org" name) dir)))))

(defun create-blog-file ()
  (funcall (create-org-file-with-dir "~/Dropbox/org/blog/")))

(setq org-capture-templates
      '(("t" "Todo" entry (file+datetree "~/Dropbox/org/work.org")
         "** TODO %?\n %i\n " :empty-lines 1)
        ("b" "Blog file" entry (file create-blog-file)
         "** New Post\n#+BLOG: coderscat.com\n#+CATEGORY:\n#+TAGS:\n#+DESCRIPTION:\n#+ATTR_WP: :syntaxhl light=true\n#+TITLE: %^{desc}\n " :empty-lines 1)
        ))

```

It’s easy to insert code snippet use `org-insert-structure-template`. Except for code, we can also insert various kinds of templates:

![2019_10_26_emacs-with-wordpress.org_20200308_122943.png](https://coderscat.com/wp-content/uploads/2019_10_26_emacs-with-wordpress.org_20200308_122943.png)

I wrote this elisp code `org-insert-image` to insert image from clipboard:

```
(defun org-insert-image ()
  (interactive)
  (let* ((path (concat default-directory "img/"))
         (image-file (concat
                      path
                      (buffer-name)
                      (format-time-string "_%Y%m%d_%H%M%S.png"))))
    (if (not (file-exists-p path))
        (mkdir path))
    (shell-command (concat "pngpaste " image-file))
    (org-insert-link nil (concat "file:" image-file) ""))
  )

```

The post [Blogging with Emacs and WordPress](https://coderscat.com/blogging-with-emacs-and-wordpress) appeared first on [CodersCat](https://coderscat.com).