WordPress.org

Support

Support » Plugins and Hacks » Twitter Tools » [Plugin: Twitter Tools] include URL to original tweet

[Plugin: Twitter Tools] include URL to original tweet

Viewing 9 replies - 1 through 9 (of 9 total)
  • Ooh, just enabled custom-fields in the screen options and saw that the tweet id is saved, so i can use that to generate the urls. You guys are awesome! 🙂

    For anyone looking for this same feature, here’s a function you can use to replace the_permalink, if you want to send it to the twitter unique tweet url.

    function twitter_permalink( $echo = true ) {
    global $post;
    
    	$twitter_username = sanitize_title_with_dashes( get_option( 'aktt_twitter_username' ) );
    	$tweet_id = get_post_meta( $post->ID, 'aktt_twitter_id', true );
    	$twitter_permalink = 'http://twitter.com/'. $twitter_username .'/status/'. $tweet_id;
    
    	if ( $echo == false )
    		return $twitter_permalink;
    	else
    		echo $twitter_permalink;
    }

    And to use it in your code, something like this:
    <a href="<?php twitter_permalink(); ?>" target="_blank">view on twitter</a>

    Or to return it in function, something like this:

    $twitter_permalink = twitter_permalink( false );
    echo '<a href="'. $twitter_permalink .'" target="_blank">view on twitter</a>';

    Plugin Contributor Alex King

    @alexkingorg

    Or you could use the built-in aktt_status_url() method… and you’d be better off using esc_url() on the final URL than sanitizing the username on retrieval.

    Hello. The method that Justin Sternberg used above has now broken with the 3.0 update to Twitter Tools. Any ideas on how to do the same thing on the new version?

    It still shows the tweet, however it does not get the tweet ID and append it to the permalink… so the link comes out to be twitter.com/username/status/ (sans tweet id).

    This leads to a broken page.

    Thanks in advance for any help

    Have you looked into Alex King’s suggestion, to use aktt_status_url()?

    I have searched high and low and I do not understand how to use it. Any advice?

    Assuming I used exactly what you had before.

    Well, i’m not sure your setup, but may try modifying the function to this:

    function twitter_permalink( $echo = true ) {
    global $post;
    
    	$twitter_username = sanitize_title_with_dashes( get_option( 'aktt_twitter_username' ) );
    	$tweet_id = get_post_meta( $post->ID, 'aktt_twitter_id', true );
    	$tweet_id = $tweet_id ? $tweet_id : get_post_meta( $post->ID, '_aktt_tweet_id', true );
    
    	if ( empty( $tweet_id ) )
    		return false;
    	$twitter_permalink = 'http://twitter.com/'. $twitter_username .'/status/'. $tweet_id;
    
    	if ( $echo == false )
    		return $twitter_permalink;
    	else
    		echo $twitter_permalink;
    }

    and to use it:

    $twitter_permalink = twitter_permalink( false );
    if ( $twitter_permalink )
    	echo '<a href="'. $twitter_permalink .'" target="_blank">view on twitter</a>';

    Actually, to use a built-in function from Twitter Tools, the function would look like:

    function twitter_permalink( $echo = true ) {
    	global $post;
    
    	$twitter_username = sanitize_title_with_dashes( get_option( 'aktt_twitter_username' ) );
    	$tweet_id = get_post_meta( $post->ID, 'aktt_twitter_id', true );
    	$tweet_id = $tweet_id ? $tweet_id : get_post_meta( $post->ID, '_aktt_tweet_id', true );
    
    	if ( empty( $tweet_id ) || empty( $twitter_username ) )
    		return false;
    	$twitter_permalink = esc_url( AKTT::status_url( $twitter_username, $tweet_id ) );
    
    	if ( $echo == false )
    		return $twitter_permalink;
    	else
    		echo $twitter_permalink;
    }

    Thank you for taking the time to reply. This works perfectly for getting the tweet ID and converting it into a usable link.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: Twitter Tools] include URL to original tweet’ is closed to new replies.
Skip to toolbar