Frage

I'm stuck. I posted this on WordPress.StackExchange and they suggested I try at WebApps.StackExchange, and they suggested I try here. So, apologies for the multiple posts if you follow all those!

I have a client blog using bit.ly pro to generate custom short urls (ie foo.co). I want to show the regular horizontal version of the Twitter button, with tweet-count, and have the link that goes to the post use their custom bit.ly pro url.

I have installed Joost de Valk's Bit.ly Shortlinks plugin, which successfully converts normal WP shortlinks (wp_get_shortlink()) to the custom Bit.ly pro URL elsewhere in the site, but Twitter seems to trump that and render everything with the default t.co domain instead.

I've looked at the suggestions from this question but using the # as the data-url doesn't work, and the suggested Twitter support pages don't seem to contain any info on how to get Bit.ly to work (though they say they're going to).

Here's the function I created to insert the button in my theme - any ideas on where I'm going wrong? this is used to insert the button both within the Loop and on single-post pages.

function tweet_this() {
    global $post;
    ob_start();
    $tweet = wp_get_shortlink();
    echo '<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><a href="http://twitter.com/share" class="twitter-share-button" data-url="' .  $tweet . '" data-counturl="' . $tweet . '" data-count="horizontal" data-via="clietname" data-text="' . get_the_title() . '">Tweet</a>';
    return ob_get_clean();  
}

In case it helps, this function does work, except it doesn't render the tweet-count:

function tweet_this() {
    global $post;
    ob_start();
    $tweet = sprintf( __('%1$s %2$s'), $post->post_title, wp_get_shortlink() );
    echo '<a class="tweethis" href="http://twitter.com/intent/tweet?text=' . urlencode( $tweet ) . ' via @clientname">Tweet this</a>';
    return ob_get_clean();  
}

Let me know if you need more info - and thanks in advance for any help you can throw my way! Michelle

War es hilfreich?

Lösung

function tweet_this() {
    global $post;
    $tweet = get_permalink(); //replace with your code
    $tweetmarkup =  '<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><a href="http://twitter.com/share" class="twitter-share-button" data-url="' .  $tweet . '" data-counturl="' . $tweet . '" data-count="horizontal" data-via="clietname" data-text="' . get_the_title() . '">Tweet</a>';
    echo $tweetmarkup;  
}

This works for me, but I don't have the WPShortlinks installed, so I replaced it with the permalink. You should be able to replace the permalink with your wp_get_shortlink and it should work.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top