Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently applying a theme option I made that enables/disables social media share buttons at the end of post's content. Currently I'm struggling with getting the social media button's dialog boxes to work properly (the url of the page does not show up inside the input on the share page). Here is my current function:

function b4b_sharing_enabled($content){
    $b4b_options = get_option('b4b_theme_display_options');
    $b4b_share_post_enable = $b4b_options['share_post_enable'];

    if ($b4b_share_post_enable && is_single() || is_page()){
        $url = get_permalink();

        $content .= '<nav class="sharethis"><ul>';
        $content .= '<li><a href="https://www.facebook.com/sharer/sharer.php?u=' . esc_url($url) . '" onclick="window.open(this.href, \'facebook-share-dialog\', \'resizable=yes,width=626,height=436\'); return false;">facebook</a></li>';
        $content .= '<li><a href="https://twitter.com/share?url=' . esc_url($url) . '" onclick="window.open(this.href, \'twitter-share-dialog\', \'resizable=yes,width=626,height=436\'); return false;">twitter</a></li>';
        $content .= '<li><a href="https://plus.google.com/share?url=' . esc_url($url) . '" onclick="window.open(this.href, \'googleplus-share-dialog\', \'resizable=yes,width=626,height=436\'); return false;">googleplus</a></li>';
        $content .= '</ul></nav>';

        return $content;
    } else {
        return $content;
    }
}
add_filter('the_content', 'b4b_sharing_enabled');

If I replace the esc_url($url) with a hardcoded web page like http://google.com/ it works fine. This leaves me to believe that something is wrong with using get_permalink() to get $url. I've tried using $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"] to get $url as well but I got the same result. Any clue to fixing this would be much appreciated, thanks.

share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.