0

I'm trying to install share buttons above the articles of my site and I found this piece of code. Starting with, my problem is that the code is displayed at the end of the articles. I would rather have the buttons at the beginning. Would you like to help me solve the problem?

here is the code:

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>&nbsp;&nbsp;
        <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.'&amp;url='.$url.'&amp;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&amp;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;
}
0

Use This Code May Help You:

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>&nbsp;&nbsp;
            <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.'&amp;url='.$url.'&amp;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&amp;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;
    }
  • Its great to hear you. Please Mark it right, it will help others. – Munish Kumar Apr 21 '18 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.