Display your latest tweet on your blog without using a plugin
Display your latest tweet on your blog without using a plugin
Many plugins are available if you’re looking for a way to display your latest tweet on your blog. But you don’t really need to install a plugin for that.
Simply paste the following code anywhere in your theme files, where you want the tweets to be displayed. Don’t forget to update the code with your username on line 3. Max items to display can be defined on line 4.
< ?php include_once(ABSPATH . WPINC . ‘/feed.php’); $rss = fetch_feed(‘https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=catswhocode’); $maxitems = $rss->get_item_quantity(3);
$rss_items = $rss->get_items(0, $maxitems);
?>
< ?php if ($maxitems == 0) echo ‘
-
No items.’;
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>