Skip to content

Instantly share code, notes, and snippets.

@wayphorier
Last active July 20, 2018 14:18
Show Gist options
  • Save wayphorier/674d876b1d7185fe9d15fe7acd83d83f to your computer and use it in GitHub Desktop.
Save wayphorier/674d876b1d7185fe9d15fe7acd83d83f to your computer and use it in GitHub Desktop.
WordPress Custom popup-share links
/**
* Выводит блок ссылок на средства публикации соцсетей
*/
function wph_share_links() {
global $post;
echo '<div class="share">';
$url = urlencode( get_permalink( $post->ID ) );
$title = urlencode( get_the_title( $post->ID ) );
$description = urlencode( get_the_excerpt( $post->ID ) );
$image = urlencode( get_the_post_thumbnail_url( $post->ID ) );
// Параметры ссылки VK
$vk = array(
'link_params' => array(
'sharer' => 'https://vk.com/share.php?',
'url' => 'url=' . $url,
'title' => '&title=' . $title,
'image' => '&image=' . $image,
'description' => '&description='. $description,
'parse' => '&noparse=true'
),
'icon' => 'vk',
'title' => 'Поделиться ВКонтакте',
'class' => 'share__vk'
);
// Параметры ссылки Facebook
$fb = array(
'link_params' => array(
'sharer' => 'http://www.facebook.com/sharer.php?s=100',
'url' => '&p[url]=' . $url,
'title' => '&p[title]=' . $title,
'image' => '&p[images][0]=' . $image,
'description' => '&p[summary]='. $description
),
'icon' => 'facebook-f',
'title' => 'Поделиться в Facebook',
'class' => 'share__fb'
);
// Параметры ссылки twitter
$tw = array(
'link_params' => array(
'sharer' => 'http://twitter.com/share?',
'url' => 'url=' . $url,
'text' => '&text=' . $title,
'via' => '&via=' . 'Your site name'
),
'icon' => 'twitter',
'title' => 'Поделиться в Twitter',
'class' => 'share__tw'
);
// Параметры ссылки Google Plus
$gp = array(
'link_params' => array(
'sharer' => 'https://plus.google.com/share?',
'url' => 'url=' . $url
),
'icon' => 'google',
'title' => 'Поделиться в Google+',
'class' => 'share__gp'
);
// Генерируем ссылки
$links = '';
foreach ( array( $vk, $fb, $tw, $gp ) as $data ) {
$links .= '<a href="' . share_link_build( $data['link_params'] ) . '" target="_blank" onclick="WphShare.me(this); return false;" class="' . $data['class'] . '" title="' . $data['title'] . '"><i class="fa fa-' . $data['icon'] . '"></i></a>';
}
$output = '<div class="pull-right">';
$output .= $links;
$output .= '</div>';
echo $output;
echo '</div>';
}
window.onload = function() {
/**
* Вызывает новое всплывающее окно со страницей публикации
* соответствующей соцсети
*/
var WphShare = {
me: function(el) {
this.popup(el.href);
},
popup: function(url) {
window.open(url, '', 'toolbar=0,status=0,width=626,height=436');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment