---
title: Sharing to social media using simple links
date: 2017-05-07
published: 2017-05-07
tags: ['technology', 'jekyll']
description: "Adding social sharing links for Facebook, Twitter and Google+ to a Jekyll site using plain HTML links instead of embedded scripts."
references:
  - '/posts/migrating-to-gitlab/'
  - '/posts/jekyll-post-archive/'
---

Allowing visitors to share pages to social media is a good way of disseminating information. The issue with the recommended methods — embedded buttons — is that they rely on adding a script to each page, which can slow down page loading or track usage across websites. HTML hyperlinks are universally supported and provide an easy way for visitors to create a post directly.

The GitHub Pages backend uses Jekyll, which conveniently stores information such as the address of each post. This can be obtained by calling `page.url`. As these links need to come from externally, you'll need the rest of your website's address included as well, obtainable via `absolute_url`:

```
{{ page.url | absolute_url }}
```

From there, it's a matter of working out the format of the links for the respective social media sites you'd like to use.

### Facebook

```
http://www.facebook.com/sharer.php?u={{ page.url | absolute_url }}&t={{ page.title }}
```

### Twitter

```
http://twitter.com/share?text={{ page.title }}&url={{ page.url | absolute_url }}&hashtags={{ page.category }}
```

### Google+

```
https://plus.google.com/share?url={{ page.url | absolute_url }}
```
