wordpress中的社交图标位置

时间:2015-05-23 02:50:35

标签: wordpress

function flx_social_sharing_buttons($content) {
    // Show this on post and page only. Add filter is_home() for home page
    if(is_singular()){

        // Get current page URL
        $shortURL = get_permalink();

        // Get current page title
        $shortTitle = get_the_title();`enter code here`

        // Construct sharing URL without using any script
        $twitterURL = 'https://twitter.com/intent/tweet?text='.$shortTitle.'&url='.$shortURL.'&via=flx';
        $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$shortURL;
        $googleURL = 'https://plus.google.com/share?url='.$shortURL;
        $tumblrURL = 'http://www.tumblr.com/share/link?url='.$shortURL;

        // Add sharing button at the end of page/page content
        $content .= '<div class="flx-social">';
        $content .= '<a class="flx-link flx-facebook" href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook"></i></a>';
        $content .= '<a class="flx-link flx-twitter" href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter"></i></a>';
        $content .= '<a class="flx-link flx-googleplus" href="'.$googleURL.'" target="_blank"><i class="fa fa-google-plus"></i></a>';
        $content .= '<a class="flx-link flx-tumblr" href="'.$tumblrURL.'" target="_blank"><i class="fa fa-tumblr"></i></a>';
        $content .= '</div>';
        return $content;
    }else{
        // if not post/page then don't include sharing button
        return $content;
    }
};
add_filter( 'the_content', 'flx_social_sharing_buttons');

我使用此代码在我的帖子下方显示社交分享按钮

我需要添加短代码功能,以便它出现在我想要的任何地方 该怎么做请帮忙

2 个答案:

答案 0 :(得分:0)

你可以用下面的代码来完成它,

<?php echo do_shortcode('[the_content]'); ?>

只是想要这个代码,你想要社交图标,你可以在那些地方获得它。

答案 1 :(得分:0)

我不确定我是否正确理解了您的问题,但希望您能够使用以下内容来解决您的问题。

如果我想重新调整功能以呈现社交分享按钮,我会先将第一行更改为

function flx_social_sharing_buttons($content = false) {

在此阶段,代码应按预期在每个帖子后添加社交分享按钮。要以编程方式或在帖子或页面中添加,您可以添加以下行,创建短代码:

// Add the [my-social-buttons] shortcode    
add_shortcode( 'my-social-buttons', 'flx_social_sharing_buttons' );
  

可从以下网址获取文档:directly call the sign_out method

     

创建短代码和其他Wordpress功能的绝佳资源:   https://codex.wordpress.org/Shortcode_API

您现在可以在帖子或页面中使用短代码。要在php文件中使用它,请执行以下操作

echo do_shortcode('[my-social-buttons]');

如果你发现你现在宁愿以编程方式使用你的函数,那么剩下要做的就是删除原来的钩子,如果你的社交分享按钮现在重复了:

// Remove or comment out
// add_filter( 'the_content', 'flx_social_sharing_buttons');