A while ago I told you how to automatically change author URL to Twitter when using Tweet Import. In this post I will give you a way to change the author displayed name as well.

It is, as usual, as simple as copying the following code and adding it to your theme “functions.php” file.

  1. // *** Requires Tweet Import Version 1.2.2 or newer ***
  2. if (!has_filter ('the_author', 'tweetimport_change_author_name_to_twitter')) {add_filter('the_author', 'tweetimport_change_author_name_to_twitter');}
  3. if (!function_exists('tweetimport_change_author_name_to_twitter')):
  4. function tweetimport_change_author_name_to_twitter($link)
  5. {
  6. global $post;
  7. global $in_comment_loop;
  8. if (in_the_loop() && !$in_comment_loop):
  9. $twitter_author_name = get_post_meta($post->ID,'tweetimport_twitter_author' , true);
  10. if (!isset($twitter_author_name) || $twitter_author_name == '')
  11. return $link;
  12. return '@' . $twitter_author_name;
  13. else :
  14. return $link;
  15. endif;
  16. }
  17. endif; //tweetimport_change_author_name_to_twitter

This code just applies a custom ‘the_author’ filter that substitutes the WordPress Author Name with Twitter user @name. 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.