embed your latest
mastodon post

I embed my most recent Mastrodon post on the page that links to my fedi account (where you can also read what 'fedi' and 'Mastodon' are) - there are many ways to do this, but mine's the simplest I've seen.

the mastodon logo, an elephant head with a big lowercase m on it, with lots of messy PHP code superimposed on it I do it with 22 lines of PHP code, reproduced below. You can plug this code straight into any page and it'll work right out of the box; all you have to do is trace down and input your account's RSS feed, which is usually at domain.net/@username.rss. I've left my own account name in place below, bolded so you know what to replace.

<?php
$xml = simplexml_load_file("https://oldbytes.space/@anomalocaris.rss");
$profile = $xml->channel->link;
$name = $xml->channel->title;
for($i = 0; $i < 1; $i++){
$link = $xml->channel->item[$i]->link;
$text = $xml->channel->item[$i]->description;
$date = $xml->channel->item[$i]->pubDate;
$aud = $xml->channel->item[$i]->enclosure->attributes();
$img = $xml->channel->item[$i]->children('media', true)->content->attributes();
$thumb = str_replace('/original/','/small/',$img);
$alt = $xml->channel->item[$i]->children('media', true)->children('media', true)->description;
if (!empty ($img)){$poster = $xml-<channel-<item[$i]-<children('media', true)-<children('media', true)-<thumbnail-<attributes();}
$alt = str_replace('"','“',$alt);
$html = '<div style="text-align:right"><a href="' . $profile . '">@' . $name . '</a> | <a href="' . $link . '">' . substr($date, 0, -9) . '</a></div>
' . $text;
if (preg_match('/\.mp4/',$img)){$html = $html . '
<video preload="none" controls poster="' . $poster . '" src="' . $img . '"><p>' . $alt . '</p></video>';}
elseif (!empty ($aud))$html = $html . '
<audio preload="none" controls src="' . $aud . '"><p>' . $alt . '</p></audio>';
elseif (!empty ($img))$html = $html . '
<a href="' . $img . '"><img class="money" src="' . $thumb . '" alt="' . $alt . '"></a>';
$html = str_replace('<a ','<a target="_blank" ',$html);
echo $html;}
?>
It's as clever as it needs to be for now - it embeds an image or media file (including alt text) if there is one and it converts any links to make them open in new tabs. If you post multiple images it only includes the first one. Here's what the above code looks like when rendered:
@anomalocaris | Sun, 25 Oct 2026 23:29

in fact I call them dumbphones. folks,

Please keep in mind that this code will download that RSS file every time someone loads the page, and your instance admin may not like that kind of traffic - you may want to ask them what they think. Alternatively, as I've done, you can set up a cronjob on your server to download the RSS file once an hour and load the data from there, to limit the load on the instance.

As per usual I publish this little snippet of code into the public domain so you may do with it whatever you want within the constraints of the laws of physics.