Using this tutorial I was able to create sharing buttons, but the problem that the code inject right after the_content();
, I would like to have the ability to call anywhere in my templates. My understanding that add_filter('the_content')
is the reason for that, so how can I change it to call it anywhere.
function social_buttons($content) {
global $post;
$permalink = get_permalink($post->ID);
$title = get_the_title();
if(!is_single() && !is_page()) {
$content = $content . '<div class="contentBottom">
<ul class="share">
<li><a href="#"><i class="fa fa-share-alt"></i>شارك</a>
<ul class="social">
<li><a href="https://www.facebook.com/sharer/sharer.php?u='.$permalink.'"
onclick="window.open(this.href, \'facebook-share\',\'width=580,height=296\');return false;"><i class="fa fa-facebook"></i></a></li>
<li><a href="http://twitter.com/share?text='.$title.'&url='.$permalink.'"
onclick="window.open(this.href, \'twitter-share\', \'width=550,height=235\');return false;"><i class="fa fa-twitter"></i></a></li>
<li><a href="https://plus.google.com/share?url='.$permalink.'"
onclick="window.open(this.href, \'google-plus-share\', \'width=490,height=530\');return false;"><i class="fa fa-google-plus"></i></a></li>
<li><a href="#"><i class="fa fa-envelope"></i></a></li>
</ul>
</li>
</ul>
<ul class="printComment">
<li><a href="javascript:window.print()" rel="nofollow"><i class="fa fa-print"></i>طباعة</a></li>
<li><a href="#"><i class="fa fa-comments-o"></i>شارك بالتعليق</a></li>
</ul></div>';
}
return $content;
}
add_filter('the_content', 'social_buttons');
return $content
there will be no output. call it likeecho social_buttons('')
with an empty string as argument to get rid of the warning.