- Joined
- Sep 15, 2014
- Messages
- 4,343
- Likes
- 8,855
- Degree
- 8
Alright, so I do mention at times that I create social icons for sharing without needing to have each page ping home to the respective network - meaning less https requests.
Well here is the code I utilize for everyone, as I find more hardcoded content I'll add it. I'm going to use tags like {{ current_page.url }} - that's PicoCMS (twig template) but you can easily adapt it to wordpress or whatever CMS you are using, or script it so jquery implements it. It's pretty simple, where {{ current_page.url }} is you input your code or hardcode the url - obviously without the {{ and }}. If you are using PicoCMS, Phile, or something based on twig templates, you don't need to edit anything in the code:
So here is a recent new page I'm working on that I utilize the exact code below with:
The code itself uses Font Awesome for the icons, you can use font awesome or not, I utilize it throughout the site, so it's readily available for users.
Full code:
--
Broken down
Facebook: Once someone clicks this, a Facebook sharing option with the URL embedded will appear. (If you are smart and have Open Graph already installed an image will also appear)
--
Twitter: Once clicked, this will populate the user's tweet with the current page url, and title of the site. (Again if you are smart and have Twitter Cards installed once the user clicks submit a nice high-resolution image with a summary will appear within the tweet)
--
Reddit: This is a trick onclick use, since it had javascript in it if you look carefully, but it works perfectly out of the box without any additional replacement of the code.
--
Email: A bit tricky, since it utilizes the old-school "mailto" html tag, but you can do some interesting stuff with it, like create the subject line, and body, and CC (or BCC) yourself if you really want to. When they click on the link, it'll open up THEIR email client with all this data filled out for them, and if you added a CC or BCC, that field will be filled out as well - cute trick For this example I'll add the cc as well:
Some more HTML mailto tricks here: http://rijamedia.com/blog/2010/12/email-tutorial-to-cc-bcc-subject-body-in-mailto-links/
--
As I find more social icons and scripts that do not add http requests to 3rd party just to share, I'll add them to this thread. (This might be hot to implement into certain wordpress themes @Ryuzaki)
Well here is the code I utilize for everyone, as I find more hardcoded content I'll add it. I'm going to use tags like {{ current_page.url }} - that's PicoCMS (twig template) but you can easily adapt it to wordpress or whatever CMS you are using, or script it so jquery implements it. It's pretty simple, where {{ current_page.url }} is you input your code or hardcode the url - obviously without the {{ and }}. If you are using PicoCMS, Phile, or something based on twig templates, you don't need to edit anything in the code:
So here is a recent new page I'm working on that I utilize the exact code below with:
The code itself uses Font Awesome for the icons, you can use font awesome or not, I utilize it throughout the site, so it's readily available for users.
Full code:
Code:
<div class="cta">
<div class="facebook button">
<a href="https://www.facebook.com/sharer/sharer.php?u={{ current_page.url }}" target="_blank"><i class="fa fa-facebook fa-lg"></i> Share</a>
</div>
<div class="twitter button">
<a href="http://twitter.com/share" target="_blank" class="twitter-share-button" data-text='{{ current_page.url }} - {{ meta.title }} - {{ site_title }}' data-count="none"><i class="fa fa-twitter fa-lg"></i> Tweet</a>
</div>
<div class="reddit button">
<a href="http://www.reddit.com/submit" onclick="window.location = 'http://www.reddit.com/submit?url=' + encodeURIComponent(window.location); return false"><i class="fa fa-reddit fa-lg"></i> Reddit</a>
</div>
<div class="email button">
<a href="mailto:?subject={{ meta.title }} - {{ site_title }}&cc=mattcutts@googly.com&body={{ meta.title }} - {{ site_title }}: {{ current_page.url }}"><i class="fa fa-envelope fa-lg"></i> Email</a>
</div>
<br>
</div>
--
Broken down
Facebook: Once someone clicks this, a Facebook sharing option with the URL embedded will appear. (If you are smart and have Open Graph already installed an image will also appear)
Code:
<div class="facebook button">
<a href="https://www.facebook.com/sharer/sharer.php?u={{ current_page.url }}" target="_blank"><i class="fa fa-facebook fa-lg"></i> Share</a>
</div>
--
Twitter: Once clicked, this will populate the user's tweet with the current page url, and title of the site. (Again if you are smart and have Twitter Cards installed once the user clicks submit a nice high-resolution image with a summary will appear within the tweet)
Code:
<div class="twitter button">
<a href="http://twitter.com/share" target="_blank" class="twitter-share-button" data-text='{{ current_page.url }} - {{ meta.title }} - {{ site_title }}' data-count="none"><i class="fa fa-twitter fa-lg"></i> Tweet</a>
</div>
--
Reddit: This is a trick onclick use, since it had javascript in it if you look carefully, but it works perfectly out of the box without any additional replacement of the code.
Code:
<div class="reddit button">
<a href="http://www.reddit.com/submit" onclick="window.location = 'http://www.reddit.com/submit?url=' + encodeURIComponent(window.location); return false"><i class="fa fa-reddit fa-lg"></i> Reddit</a>
</div>
--
Email: A bit tricky, since it utilizes the old-school "mailto" html tag, but you can do some interesting stuff with it, like create the subject line, and body, and CC (or BCC) yourself if you really want to. When they click on the link, it'll open up THEIR email client with all this data filled out for them, and if you added a CC or BCC, that field will be filled out as well - cute trick For this example I'll add the cc as well:
Code:
<div class="email button">
<a href="mailto:?subject={{ meta.title }} - {{ site_title }}&cc=mattcutts@googly.com&body={{ meta.title }} - {{ site_title }}: {{ current_page.url }}"><i class="fa fa-envelope fa-lg"></i> Email</a>
</div>
Some more HTML mailto tricks here: http://rijamedia.com/blog/2010/12/email-tutorial-to-cc-bcc-subject-body-in-mailto-links/
--
As I find more social icons and scripts that do not add http requests to 3rd party just to share, I'll add them to this thread. (This might be hot to implement into certain wordpress themes @Ryuzaki)
Last edited: