# Writing an org-capture template and defun for blog posts

**URL:** <https://forum.systemcrafters.net/t/writing-an-org-capture-template-and-defun-for-blog-posts/1624>\
**Category:** Emacs\
**Tags:** emacs-lisp, emacs\
**Created:** [May 23, 2025, 7:35am UTC](https://forum.systemcrafters.net/t/writing-an-org-capture-template-and-defun-for-blog-posts/1624 "2025-05-23T07:35:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peregrinator](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@peregrinator](https://forum.systemcrafters.net/u/peregrinator)\
**Post date:** [May 23, 2025, 7:35am UTC](https://forum.systemcrafters.net/t/writing-an-org-capture-template-and-defun-for-blog-posts/1624/1 "2025-05-23T07:35:47Z")

</div>

hi! I’m new here and an Emacs noob of about four years now. I’m currently trying to set up a website using `org-publish` for building (which I’m pretty much done with) and an `org-capture` template with a supporting function for writing blog posts.

now, getting down to specific, my setup has blog posts in a specific directory and I’ve just moved from an `ox-hugo`/Hugo based setup here so posts are all individual org files. so I want the function to help take the post title (from a prompt) and generate a slug/filename and to reuse the title as the title of the org file. i also want to prompt for a description. so far, I’ve written this much, badly, and it doesn’t work. it doesn’t even allow me to select a capture template when i do `C-c c` or run `org-capture`

and `org-hugo-slug` is a function that makes a slug out of the title string, reused from `ox-hugo`

```auto
 (defun org-new-blog-post ()
      (setq org-new-blog-post-date (format-time-string (org-time-stamp-format :long :inactive) (org-current-time)))
      (setq org-new-blog-post-title (read-string "Post Title: "))
      (setq org-new-blog-post-fname (org-hugo-slug title))
      (setq org-new-blog-post-description (read-string "Description: "))
      ;; CHANGED THIS BIT:
      (find-file (expand-file-name (format "%s.org" org-new-blog-post-fname) "~/git/personal/blog/org/blog/")))
    
(setq org-capture-templates
    '(("n" "new post"
    plain
    (function org-new-blog-post)
    "%(format \"#+title: %s\n#+date: %s\n#+description: %s\n\n\" org-new-blog-post-title org-new-blog-post-date org-new-blog-post-description)")))

```

so, any help on how I could go about this?

---

<div class="post-metadata">

**Author:** ![peregrinator](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@peregrinator](https://forum.systemcrafters.net/u/peregrinator)\
**Post date:** [May 26, 2025, 5:08am UTC](https://forum.systemcrafters.net/t/writing-an-org-capture-template-and-defun-for-blog-posts/1624/2 "2025-05-26T05:08:59Z")

</div>

So I’d asked a couple of friends and one of them was kind enough to help me write this function. i mean, they wrote it and i just changed it up to make it work according to my needs:

```auto
(with-eval-after-load 'org-capture
  (defun taingram/org-new-blog-post ()
    "Gets user input for blog post title and uses it to construct the
filename to create. Also uses the title in the capture form so I don't have to type it out again."
    (interactive)
    (let* ((title (read-string "Post Title: "))
           (filename
            (read-string "Filename: "
                         (concat (org-hugo-slug title) ".org"))))
      (set-buffer (find-file-noselect
                   (file-name-concat "~/git/personal/blog/org/drafts/" filename)))
      (insert "#+title: " title)
      (newline))))

(setq org-capture-templates
      '(("b" "New blog post"
         plain
         (function taingram/org-new-blog-post)
         "#+date: %u
#+description: %^{Description} \n
%?"))

```

the title doesn’t show up till after the file is opened but it works. for a version of this that shows the title too [paste.sr.ht](https://paste.sr.ht/~taingram/02feb68b1852cdcdecb2f43f6dbbc0c4e7e35e11)
