In my previous post (Display Twitter User Avatar in Themes such as P2 for Wordpress) I provided a hack to replace the author avatar with the Twitter author image.
In this hack, I will show you how to automatically change the Author URL to link to the Twitter user profile page instead of showing the posts by a specific author.
This is mostly required when you are importing lists or favorites from Twitter. In that case, the default page showing the different posts by a user will generally not be preferable and it would make more sense to show the Twitter profile page of the original Twitter author.
As usual, the hack is simple. Just copy the following to your theme “functions.php” file.
// *** Requires Tweet Import Version 1.2.2 or newer ***
if (!has_filter ('author_link', 'tweetimport_change_author_url_to_twitter')) {add_filter('author_link', 'tweetimport_change_author_url_to_twitter');}
if (!function_exists('tweetimport_change_author_url_to_twitter')):
function tweetimport_change_author_url_to_twitter($link)
{
global $post;
global $in_comment_loop;
if (in_the_loop() && !$in_comment_loop):
$twitter_author_name = get_post_meta($post->ID,'tweetimport_twitter_author' , true);
if (!isset($twitter_author_name) || $twitter_author_name == '')
return $link;
return 'http://twitter.com/' . $twitter_author_name;
else :
return $link;
endif;
}
endif; //tweetimport_change_author_url_to_twitter
This code just applies a custom ‘author_link’ filter that substitutes the Author URL generated by WordPress with a link to the Twitter user profile. It uses the value in the ‘tweetimport_twitter_author’ Custom Field created by Tweet Import and whose content is the author name of the original Twitter User @name.

Comments