Javascript 在内容上方显示共享按钮

Javascript 在内容上方显示共享按钮,javascript,php,wordpress,Javascript,Php,Wordpress,嘿,我有一个插件,我在我的wordpress博客上激活了它。这是工作,但我想分享按钮来上面的内容。我找不到任何办法来做那件事。请帮我做到这一点,请不要告诉我使用其他插件 <?php /* Plugin Name: WordPress Social Share Plugin Description: Simple Social Share Buttons - Facebook Like, Twitter, Google +, Buffer, LinkedIn, StumbleUpon, Pi

嘿,我有一个插件,我在我的wordpress博客上激活了它。这是工作,但我想分享按钮来上面的内容。我找不到任何办法来做那件事。请帮我做到这一点,请不要告诉我使用其他插件

<?php
/*
Plugin Name: WordPress Social Share Plugin
Description: Simple Social Share Buttons - Facebook Like, Twitter, Google +, Buffer, LinkedIn, StumbleUpon, Pinterest Share Buttons after post contents.
Version: 1.0.7
Author: Ataul Ghani
Author URI: http://freebloggingtricks.com/
*/
/**
 * This file is part of facebook-twitter-googleplus-linkedin-buffer-share-buttons.
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with facebook-twitter-googleplus-linkedin-buffer-share-buttons.  If not, see <http://www.gnu.org/licenses/>.
 */
        /*
        Contents:
        1.Head js: Pinterest,Google + 
        2.Footer js: Twitter,Linkedin
        3.Get the Image for Pinterest
        4.Display the Social Share Buttons and Print Button
        */

##### 1. Head js: Pinterest,Google +#####################

function FTGSB_head() {
if (is_single()) { ?> 
<script type="text/javascript">
(function() {
    window.PinIt = window.PinIt || { loaded:false };
    if (window.PinIt.loaded) return;
    window.PinIt.loaded = true;
    function async_load(){
        var s = document.createElement("script");
        s.type = "text/javascript";
        s.async = true;
        if (window.location.protocol == "https:")
            s.src = "https://assets.pinterest.com/js/pinit.js";
        else
            s.src = "http://assets.pinterest.com/js/pinit.js";
        var x = document.getElementsByTagName("script")[0];
        x.parentNode.insertBefore(s, x);
    }
    if (window.attachEvent)
        window.attachEvent("onload", async_load);
    else
        window.addEventListener("load", async_load, false);
})();
</script>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<?php }
 }
add_action('wp_head', 'FTGSB_head',20);

############2.Footer js: Twitter,linkedin Share#################
function FTGSB_footer() {
    if (is_single()) { ?> 
        <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
        <script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
    <?php }
 }
add_action('wp_footer', 'FTGSB_footer');


###############3.Get the Image for Pinterest#####################

function pinterest_image() {
  global $post, $posts;
  //if you set p-img custom field, then set it as pinterest_image
  $pinterest_image = get_post_meta($post->ID, 'p-img', true);  

  //if not,get the first image in the post as pinterest_image
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  //return pinterest_image URL
  if(empty($pinterest_image)){    
    $pinterest_image = $first_img;
  }
  return $pinterest_image;
}


###############4.Display the Social Share Buttons################

add_filter ('the_content', 'FTGSB');
function FTGSB($content) {
if(is_single()) {
global $post, $posts;
$content.= '
<style>#socialbuttonnav li{list-style:none;overflow:hidden;margin:1 auto;background:none;overflow:hidden;width:92px; height:25px; line-height:10px; margin-right:1px; padding: 20px 0px 0px 0px; float:left; text-align:center;}</style>
<ul id="socialbuttonnav">
<li><!-- Facebook like--><iframe src="//www.facebook.com/plugins/like.php?href='.urlencode(get_permalink($post->ID)).
'&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;appId=220231561331594" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe></li>
<li><!-- Google plus one--><div class="g-plusone" data-size="tall" data-annotation="inline" data-width="120"></div></li>
<li><!-- Twitter--><a name="twitter_share" data-count="horizontal" href="http://twitter.com/share" class="twitter-share-button" >Tweet</a></li>
<li><!-- Buffer--><a href="http://bufferapp.com/add" class="buffer-add-button" data-count="horizontal" >Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></li>
<li><!-- linkedin--><div><script src="//platform.linkedin.com/in.js" type="text/javascript">
 lang: en_US
</script>
<script type="IN/Share" data-counter="right"></script></div></li>
<li><!-- stumbleupon--><div><script src="http://www.stumbleupon.com/hostedbadge.php?s=1"></script></div></li>
<li><!-- Pinterest like--> <a href="http://pinterest.com/pin/create/button/?url='.urlencode(get_permalink($post->ID)).
'&media='.pinterest_image().'" class="pin-it-button" count-layout="horizontal">Pin It</a></li>
</ul>';
}
return $content;
}

(功能(){
window.PinIt=window.PinIt | |{loaded:false};
if(window.PinIt.load)返回;
window.PinIt.load=true;
函数异步加载(){
var s=document.createElement(“脚本”);
s、 type=“text/javascript”;
s、 异步=真;
如果(window.location.protocol==“https:”)
s、 src=”https://assets.pinterest.com/js/pinit.js";
其他的
s、 src=”http://assets.pinterest.com/js/pinit.js";
var x=document.getElementsByTagName(“脚本”)[0];
x、 parentNode.insertBefore(s,x);
}
如果(窗口附件)
attachEvent(“onload”,异步加载);
其他的
addEventListener(“加载”,异步加载,false);
})();
(功能(){
var po=document.createElement('script');po.type='text/javascript';po.async=true;
po.src=https://apis.google.com/js/plusone.js';
var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(po,s);
})();

尝试更改
add_filter('the_content','FTGSB')
添加过滤器('the_content','FTGSB',1)

更新:尝试以下操作:

add_filter ('the_content', 'FTGSB');
function FTGSB($content) {
if(is_single()) {
global $post, $posts;
$prepend = '
<style>#socialbuttonnav li{list-style:none;overflow:hidden;margin:1 auto;background:none;overflow:hidden;width:92px; height:25px; line-height:10px; margin-right:1px; padding: 20px 0px 0px 0px; float:left; text-align:center;}</style>
<ul id="socialbuttonnav">
<li><!-- Facebook like--><iframe src="//www.facebook.com/plugins/like.php?href='.urlencode(get_permalink($post->ID)).
'&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;appId=220231561331594" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe></li>
<li><!-- Google plus one--><div class="g-plusone" data-size="tall" data-annotation="inline" data-width="120"></div></li>
<li><!-- Twitter--><a name="twitter_share" data-count="horizontal" href="http://twitter.com/share" class="twitter-share-button" >Tweet</a></li>
<li><!-- Buffer--><a href="http://bufferapp.com/add" class="buffer-add-button" data-count="horizontal" >Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></li>
<li><!-- linkedin--><div><script src="//platform.linkedin.com/in.js" type="text/javascript">
 lang: en_US
</script>
<script type="IN/Share" data-counter="right"></script></div></li>
<li><!-- stumbleupon--><div><script src="http://www.stumbleupon.com/hostedbadge.php?s=1"></script></div></li>
<li><!-- Pinterest like--> <a href="http://pinterest.com/pin/create/button/?url='.urlencode(get_permalink($post->ID)).
'&media='.pinterest_image().'" class="pin-it-button" count-layout="horizontal">Pin It</a></li>
</ul>';
}
$content = $prepend . '<br />' . $content;
return $content;
}
add_filter('the_content','FTGSB');
功能FTGSB($content){
if(is_single()){
全球$员额,$员额;
$prepend=
#socialbuttonnav li{列表样式:无;溢出:隐藏;边距:1自动;背景:无;溢出:隐藏;宽度:92px;高度:25px;线宽:10px;右边距:1px;填充:20px 0px 0px 0px;浮动:左;文本对齐:中心;}
  • 朗:恩
'; } $content=$prepend.
。$content; 返回$content; }