我正在尝试在我的站点文章上方安装共享按钮,我发现了这段代码。首先,我的问题是代码显示在文章的末尾。我宁愿把按钮放在开头。你愿意帮我解决这个问题吗?
代码如下:
add_filter(\'the_content\', \'br_content_with_social_buttons\');
function br_content_with_social_buttons($content){
$url = urlencode(get_permalink());
// Get current page title
$title = str_replace(\' \', \'%20\', get_the_title());
$blog_title = get_bloginfo(\'name\');
$content .=\'
<div id="social-share">
<strong><span>Sharing is caring</span></strong> <i class="fa fa-share-alt"></i>
<a href="https://www.facebook.com/sharer.php?u=\'.$url.\'" target="_blank" class="facebook"><i class="fa fa-facebook"></i> <span>Share</span></a>
<a href="https://plus.google.com/share?url=\'.$url.\'" target="_blank" class="gplus"><i class="fa fa-google-plus"></i> <span>+1</span></a>
<a href="https://twitter.com/intent/tweet?text=\'.$title.\'&url=\'.$url.\'&via=YOUR_TWITTER_HANDLE_HERE" target="_blank" class="twitter"><i class="fa fa-twitter"></i> <span>Tweet</span></a>
<a href="http://www.linkedin.com/shareArticle?mini=true&url=\'.$title.\'" target="_blank" class="linkedin"><i class="fa fa-linkedin"></i> <span>Share</span></a>
<a href="whatsapp://send?text=\'.$title.\' \'.$url.\'" target="_blank" class="whatsapp"><i class="fa fa-whatsapp"></i> <span>Share</span></a>
</div>\';
return $content;
}
最合适的回答,由SO网友:Munish Kumar 整理而成
使用此代码可以帮助您:
add_filter(\'the_content\', \'br_content_with_social_buttons\');
function br_content_with_social_buttons($content){
$url = urlencode(get_permalink());
// Get current page title
$title = str_replace(\' \', \'%20\', get_the_title());
$blog_title = get_bloginfo(\'name\');
$sharebuttons =\'
<div id="social-share">
<strong><span>Sharing is caring</span></strong> <i class="fa fa-share-alt"></i>
<a href="https://www.facebook.com/sharer.php?u=\'.$url.\'" target="_blank" class="facebook"><i class="fa fa-facebook"></i> <span>Share</span></a>
<a href="https://plus.google.com/share?url=\'.$url.\'" target="_blank" class="gplus"><i class="fa fa-google-plus"></i> <span>+1</span></a>
<a href="https://twitter.com/intent/tweet?text=\'.$title.\'&url=\'.$url.\'&via=YOUR_TWITTER_HANDLE_HERE" target="_blank" class="twitter"><i class="fa fa-twitter"></i> <span>Tweet</span></a>
<a href="http://www.linkedin.com/shareArticle?mini=true&url=\'.$title.\'" target="_blank" class="linkedin"><i class="fa fa-linkedin"></i> <span>Share</span></a>
<a href="whatsapp://send?text=\'.$title.\' \'.$url.\'" target="_blank" class="whatsapp"><i class="fa fa-whatsapp"></i> <span>Share</span></a>
</div>\';
return $sharebuttons.$content;
}