以下是添加自定义共享按钮的简单方法(只需将此代码放置在您希望显示共享按钮的位置):
<?php
$twitter_username = \'your_twitter_username\';
$shortURL = esc_url(get_permalink());
$shortTitle = esc_attr(get_the_title());
$imgURL = wp_get_attachment_url( get_post_thumbnail_id() );
$twitterURL = \'https://twitter.com/intent/tweet?text=\'.$shortTitle.\'&url=\'.$shortURL.\'&via=\'.$twitter_username;
$facebookURL = \'https://www.facebook.com/sharer/sharer.php?u=\'.$shortURL;
$googleURL = \'https://plus.google.com/share?url=\'.$shortURL;
$pinURL = \'http://pinterest.com/pin/create/button/?url=\'.$shortURL.\'&media=\'.$imgURL.\'&description=\'.$shortTitle;
?>
<a class="facebook-btn" href="<?php echo $facebookURL; ?>" target="_blank" onclick="window.open(\'<?php echo $facebookURL; ?>\', \'popupwindow\', \'scrollbars=no,width=500,height=400\');return true">Share on Facebook</a>
<a class="google-btn" href="<?php echo $googleURL; ?>" target="_blank" onclick="window.open(\'<?php echo $googleURL; ?>\', \'popupwindow\', \'scrollbars=no,width=500,height=400\');return true">Share on Google Plus</a>
<a class="twitter-btn" href="<?php echo $twitterURL; ?>" target="_blank" onclick="window.open(\'<?php echo $twitterURL; ?>\', \'popupwindow\', \'scrollbars=no,width=500,height=300\');return true">Tweet on Twitter</a>
<a class="pinterest-btn" href="<?php echo $pinURL; ?>" target="_blank" onclick="window.open(\'<?php echo $pinURL; ?>\', \'popupwindow\', \'scrollbars=no,width=700,height=500\');return true">Pin on Pinterest</a>
现在,您需要做的是为这些类添加一些样式:
.facebook-btn
.google-btn
.twitter-btn
.pinterest-btn
希望这对你有帮助。