这里有一个使用genericons的解决方案。原始代码派生自this question 我问了,托肖回答了我的问题,所以他得到了这个答案中的原始代码。看看吧here
首先,下载并安装genericon pack 在您的主题中。将genericon样式表排队
function enqueue_genericon_style() {
wp_enqueue_style( \'genericons\', get_template_directory_uri() . \'/genericons/genericons.css\', array(), \'3.0.2\' );
}
add_action( \'wp_enqueue_scripts\', \'enqueue_genericon_style\' );
将以下内容添加到函数中。php。这些函数通过添加共享url和genericons完成所有的艰苦工作
function pietergoosen_social_share_buttons() {
$services = array (
\'facebook\' => array (
\'url\' => \'https://www.facebook.com/sharer/sharer.php?u=%1$s\',
\'text\' => esc_attr(__(\'Share on Facebook.\', \'pietergoosen\' )),
\'icon\' => \'<span class="genericon genericon-facebook"></span>\'
),
\'twitter\' => array (
\'url\' => \'http://twitter.com/home/?status=%1$s%%20-%%20%2$s\',
\'text\' => esc_attr(__(\'Tweet this post!\', \'pietergoosen\' )),
\'icon\' => \'<span class="genericon genericon-twitter"></span>\'
),
\'googleplus\' => array (
\'url\' => \'https://plus.google.com/share?url=%1$s\',
\'text\' => esc_attr(__(\'Google+1.\', \'pietergoosen\' )),
\'icon\' => \'<span class="genericon genericon-googleplus"></span>\'
),
\'linkedin\' => array (
\'url\' => \'https://www.linkedin.com/shareArticle?mini=true&url=%1$s&title=%2$s&summary=%3$s&source=%4$s\',
\'text\' => esc_attr(__(\'linkedin.\', \'pietergoosen\' )),
\'icon\' => \'<span class="genericon genericon-linkedin"></span>\'
),
\'reddit\' => array (
\'url\' => \'http://reddit.com/submit?url=%1$s&title=%2$s\',
\'text\' => esc_attr(__(\'Reddit.\', \'pietergoosen\' )),
\'icon\' => \'<span class="genericon genericon-reddit"></span>\'
),
\'stumbleupon\' => array (
\'url\' => \'http://www.stumbleupon.com/submit?url=%1$s&title=%2$s\',
\'text\' => esc_attr(__(\'StumbleUpon.\', \'pietergoosen\' )),
\'icon\' => \'<span class="genericon genericon-stumbleupon"></span>\'
),
\'digg\' => array (
\'url\' => \'http://digg.com/submit?phase=2&url=%1$s&title=%2$s\',
\'text\' => esc_attr(__(\'Digg this post!\', \'pietergoosen\' )),
\'icon\' => \'<span class="genericon genericon-digg"></span>\'
),
\'gmail\' => array (
\'url\' => \'https://mail.google.com/mail/?view=cm&fs=1&to&su=%1$s&t=%2$s\',
\'text\' => esc_attr(__(\'Share with Gmail\', \'pietergoosen\' )),
\'icon\' => \'<span class="genericon genericon-mail"></span>\'
)
);
$title = the_title_attribute( array ( \'echo\' => FALSE ) );
$url = urlencode( get_permalink() );
$summary = the_excerpt();
$source = \'\';
print \'<h4>\' . __( \'Share this post with others\', \'pietergoosen\' ) . \'</h4>\';
echo \'<div class="socialgenericons service">\';
foreach ( $services as $name => $service )
{
$href = sprintf( $service[\'url\'], $url, urlencode( $title ), urlencode( $summary ), urlencode( $source ) );
$genericon = $service[\'icon\'];
printf(
\'<a href="%1$s" title="%2$s" alt="%2$s">%3$s</a>\',
$href,
$service[\'text\'],
$genericon
);
}
echo \'</div>\';
}
现在添加
<?php pietergoosen_social_share_buttons(); ?>
在您的内容中。需要显示按钮的php。
要在单击链接时打开弹出窗口,请在enqueue_genericon_style()
作用
wp_enqueue_script( \'pietergoosen-socialshare\', get_template_directory_uri() . \'/js/socialshare.popup.js\', array( \'jquery\' ), \'\' , true );
现在在你的主题中创建一个js文件夹,如果你没有的话。创建一个名为
socialshare.popup.js
在js文件夹中。现在在该文件中添加以下内容
jQuery(document).ready(function($) {
jQuery(\'.socialgenericons.service a\').live(\'click\', function(){
newwindow=window.open($(this).attr(\'href\'),\'\',\'height=450,width=700\');
if (window.focus) {newwindow.focus()}
return false;
});
});
这应该可以奏效。您的按钮将如下所示。您只需要相应地设置genericons的样式
EDIT
我使用自定义摘录,所以我将其更改为
the_excerpt()
就本答案而言,否则将出现致命错误。