Skip to content

Instantly share code, notes, and snippets.

@nmyers
Last active March 6, 2018 11:09
Show Gist options
  • Save nmyers/d5d78fc32e458d309eab4fb89a258f1b to your computer and use it in GitHub Desktop.
Save nmyers/d5d78fc32e458d309eab4fb89a258f1b to your computer and use it in GitHub Desktop.
Social Share #wp
<?php
function add_opengraph_markup() {
if (is_single()) {
global $post;
$twitter_handle = '';
$image = get_image(get_field('main_image'),'692x410');
$description = substr(strip_tags($post->post_content),0,200) . '...';
?>
<meta property="og:title" content="<?php the_title(); ?>" />
<meta property="og:type" content="article" />
<meta property="og:image:url" content="<?=$image?>" />
<meta property="og:url" content="<?php the_permalink(); ?>" />
<meta property="og:description" content="<?=$description?>" />
<meta property="og:site_name" content="<?=get_bloginfo('name')?>" />
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@<?=$twitter_handle?>">
<meta name="twitter:title" content="<?php the_title(); ?>">
<meta name="twitter:description" content="<?=$description?>">
<meta name="twitter:image" content="<?=$image?>">
<?php
}
}
add_action('wp_head', 'add_opengraph_markup');
;(function($){
$.fn.customerPopup = function (e, intWidth, intHeight, blnResize) {
e.preventDefault();
intWidth = intWidth || '500';
intHeight = intHeight || '400';
strResize = (blnResize ? 'yes' : 'no');
var strTitle = ((typeof this.attr('title') !== 'undefined') ? this.attr('title') : 'Social Share'),
strParam = 'width=' + intWidth + ',height=' + intHeight + ',resizable=' + strResize,
objWindow = window.open(this.attr('href'), strTitle, strParam).focus();
}
/* ================================================== */
$(document).ready(function ($) {
$('.social-links a').on("click", function(e) {
$(this).customerPopup(e);
});
});
}(jQuery));
- $url = urlencode(get_the_permalink())
- $base_url = urlencode(get_bloginfo("url"))
- $title = urlencode(get_the_title())
- $via = '';
- $twitter_link = "https://twitter.com/intent/tweet?text={$title}&url={$url}&via=$via"
- $facebook_link = "http://www.facebook.com/share.php?u=$url";
- $linkedin_link = "http://www.linkedin.com/shareArticle?mini=true&url=$url&title=$title&source=$base_url"
ul.social-links
li
a(href!=$twitter_link)
img(src!=svg_icon("twitter"))
li
a(href!=$facebook_link,target='_new')
img(src!=svg_icon("facebook"))
li
a(href!=$linkedin_link)
img(src!=svg_icon("linkedin"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment