Evernote Site Memory tagger for WordPress
Evernote introduced Site Memory today, providing an easy way to help people clip to Evernote from your site while maintaining control over how your content appears and is attributed. While some instructions are provided for WordPress, some of us will obviously want to customize things a little further.
Brett Kelly posted a quick PHP script on the Evernote WordPress docs to include the first three tags from your post as suggested tags in the clipper. I wanted to weight these, though, so here’s my version…
<a href="javascript:void()" title="Clip to Evernote" class="evernoteclip"
onclick="Evernote.doClip({ title: '<?php the_title_attribute(); ?>',
providerName: 'Brett Terpstra',
url: '<?php the_permalink(); ?>',
contentId: 'post-<?php the_ID(); ?>-clip',
suggestTags: '<?php
if (get_post_meta($post->ID, 'evernoteTags', true)) {
echo get_post_meta($post->ID, 'evernoteTags', true);
} else {
$posttags = get_the_tags();
$out = array();
if ($posttags) {
foreach($posttags as $tag) {
$out[trim($tag->name)] = intval($tag->count);
}
ksort($out,SORT_NUMERIC);
echo implode(array_keys(array_slice($out, 0, 3)),',');
}
}?>'});return false;">
<img src="<?php bloginfo('template_url'); ?>/images/evernoteclipper.png" alt="Evernote Clipper Icon"/>
</a>
It first checks for a custom field called “evernoteTags,” so you can override the whole thing by specifying up to three tags in a custom field in the post editor. The tags should be separated by commas, spaces aren’t important: “tag1,tag2,tag3”, no quotes. Moving on…
The rest of the code grabs all of the tags for the post and their use counts on your site, sorts by the use count and outputs the tag names. Pretty simple.
I should also note that the JavaScript library for the clipper weighs in at 33k compressed, so it’s not a lightweight addition to your blog. I grabbed the online source, minified it and am serving it from a CDN, so the hit was minimized, but still there. I’m also loading the clipper image from my CDN, just to avoid the extra offsite hit. I may eventually attempt to lazy load the script only when the link is clicked, but this works for now.