WordPress.org

Ready to get started?Download WordPress

Forums

Twitter Tools
include URL to original tweet (10 posts)

  1. Justin Sternberg
    Member
    Posted 2 years ago #

    Would it be possible to add to the importer the ability to include a link to the actual tweet on twitter.com? I'm using this plugin to backup my twitter profile, and the only bummer is that I have no way of getting back to that tweet on twitter.com.

    http://wordpress.org/extend/plugins/twitter-tools/

  2. Justin Sternberg
    Member
    Posted 2 years ago #

    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! :)

  3. Justin Sternberg
    Member
    Posted 2 years ago #

    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>';
  4. Alex King
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  5. shaunklink
    Member
    Posted 1 year ago #

    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

  6. Justin Sternberg
    Member
    Posted 1 year ago #

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

  7. shaunklink
    Member
    Posted 1 year ago #

    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.

  8. Justin Sternberg
    Member
    Posted 1 year ago #

    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>';
  9. Justin Sternberg
    Member
    Posted 1 year ago #

    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;
    }
  10. shaunklink
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic