使用此tutorial 我能够创建共享按钮,但代码插入后的问题the_content();
, 我想有能力调用我的模板中的任何地方。我的理解是add_filter(\'the_content\')
这就是原因,所以我怎样才能把它改成随处可见。
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\');