I use org-mode to publish a blog which is based on org files in a particular directory. I've customized values in html-head, html-preamble, and html-postamble with some Bootstrap code to get the desired html code marked up and everything works well. Accordingly, I've set org-html-head-include-default-style and org-html-head-include-scripts to nil.

I also sometimes use org-mode to export files in other locations to html which I may sometimes share (e.g., with coworkers). However, because I've set org-html-head-include-default-style and org-html-head-include-scripts to nil, those exports are boring (lack HTML tags that are included by default). I'd like to toggle org-html-head-include-default-style and org-html-head-include-scripts depending on where I'm publishing from (e.g., nil when exporting from my blog directory, other t when exporting from anywhere else). How do I achieve this?

My org-mode config is something like the following:

(setq org-html-htmlize-output-type 'css)
(setq org-html-head-include-default-style nil)
(setq org-html-head-include-scripts nil)

(setq org-publish-project-alist
         :base-directory "~/blog/content/"
         :base-extension "org"
         :publishing-directory "/ssh:[email protected]#22:/blog/"
         :recursive t
         :html-head "<!-- 3rd party css and js -->
<link rel=\"stylesheet\" type=\"text/css\" href=\"https://blog.com/site/3rdParty.css\"/>
<script src=\"https://blog.com/site/3rdParty.js\"></script>

<!-- Site css and js -->
<link rel=\"stylesheet\" type=\"text/css\" href=\"https://blog.com/site/site.css\"/>
<script src=\"https://blog.com/site/site.js\"></script>"
         :html-preamble "... preamble code ..."
         :html-postamble "... postamble code ...")))

Do I need to create some function (to toggle org-html-head-include-default-style and org-html-head-include-scripts) and a hook for org-publish depending on my present working directory?

1 Answer 1


You should be able to use directory-local variables for this: do C-h i g(emacs)Per-directory local variables RET to find out more information.

Briefly, create a file named .dir-locals.el in your blog directory where the Org mode files that you publish are kept. Put the following in the file:

((org-mode . ((org-html-head-include-default-style . nil)
              (org-html-head-include-scripts . nil))))

Every Org mode file in that directory will have those two variables locally set to nil. Other Org mode files in other directories will not be affected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.