Adding image captions to Ghost

For some reason Ghost doesn't support image captions by default. Lots of Jekyll themes and Medium both support image captions out of the box. Not sure what the reasoning is since it's fairly easy to use JavaScript to create the image captions and a modification to the Casper theme is definitely not out of the question.

The open source Chiara theme, has a small JavaScript snippet which will add a caption to all of the images with alt text specified.

![alt text][image]

Copy the following snippet into the Blog Footer form of the Code Injection entry in your Ghost installation:

    // Creates Captions from Alt tags
    $(".post-content img").each(
        function() {
            // Let's put a caption if there is one
            if ($(this).attr("alt")) {
                    '<figure class="image"></figure>'
                    '<figcaption>' +
                        "alt") +

Then you want to add the following CSS snippet to the Blog Header section:

.post .post-content figcaption {
    font-weight: 400;
    font-style: italic;
    font-size: 16px;
    line-height: 1.3;
    color: #666665;
    outline: 0;
    z-index: 300;
    text-align: center;

It should look a little something like this:

This caption is an example of what it might look like

Now if you save everything, your blog should have freshly cut image captions. Of course this isn't done on the server side so there could be some slight lag in processing but it should be fairly unnoticeable.

Hopefully the Ghost team comes through with actual image captions soon.

Kevin Chung

I like doing computer stuff, playing chess, and playing video games. I ran CSAW CTF for a couple of years and I wrote CTFd which is a popular Capture The Flag framework.

Subscribe to Kevin Chung

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!