Adding permalink to your Jekyll site


Permalink provides us easy way of sharing specific part of our blogs to the rest of the world. However, vanilla Jekyll only support permalinks to each posts, not sections, images, or paragraphs.

In this site, I’ll only add permalink to the headings. In html terms: permalinks will be added to h1, h2, h3, h4, h5, h6.

Others html elements like paragraphs p or images p > img can also be permalinked, however they need more java scripting. For more details as how to permalink them, see :link: this blog post by Brian Drupieski.

How to …

To add permalinks, we need to add the following to _layouts/post.html:

<script src=""></script>
<script src="" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="   crossorigin="anonymous"></script>

 $(function() {
         anchors.options.visible = 'always';
   <!--  anchors.options.icon = ''; -->
         anchors.add('.post-content > h1, h2, h3, h4, h5, h6');

I’ve decided to use a CDN to add anchor.js to our site, this means we need to have internet connection to use it. Another way is to embed them directly to our site. First, we need to download anchor.min.js and jquery-3.6.0.min.js and put them in assets/global/. Then change:

<script src=""></script>
<script src="" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="   


<script src=""></script>
<script src=""></script>

That’s it! You are all done! Enjoy sharing your knowledge to the world.

My sites uses a paragraph (‘p’ in html) to display logo. This means it will also be permalinked.

To overcome this I need to change the following in _includes/header.html:

<p class="logo"><a href="/">Lost Electron ⚛️</a></p>


<div class="logo"><a href="/">Lost Electron ⚛️</a></div>

Author | Chengcheng Xiao

Currently a PhD student at Imperial College London. Predicting electron behaviour since 2016.