The Definitive Location
/avatar/username
you get redirected to the avatar for that username. You can add ?s=250 to pass the size to the other side. This is the same query used by Gravatar. Right now, this calls the gravatar URL and does a temporary redirect to it, setting cache control headers to save the redirect. This means that there could be up to two http queries per avatar image. In a future version, I might actually serve the avatar locally. I got tired of broken URLs for my image. Now, the same link will always produce my image.A lot of the code focused on fixing the storage and display of media. Whenever you save a post, your content is searched for image, video, and audio tags. If there are any, it will ignore anything in these properties sent by Micropub or saved otherwise. If it finds none, it will. This should hopefully reduce duplicate displays.
Shortly after 3.4.0 went out, I found another bug, so quickly released 3.4.1. If additional bugs are found, I’ll quickly iterate.
First, four years later, we need to recap, update, and expand what we discussed last time.
Before you start, you need to clean up two very simple things.
Where do you start?
Add h-entry and h-feed in the proper places. See Part 1 for some sample code on how to do that using the body_class and post_class filters. You could also add it manually by surrounding your post, class="h-entry"
, and surrounding all the posts in an archive/feed page with an element that has class="h-feed"
Congratulations, you’ve now marked up your posts as posts and your feeds as feeds.
Now that we’ve marked up feeds and posts, we want to get down deeper…namely, inside your posts. We want to mark up things like author, publish date, etc.
In most themes, time is already marked up, something like this, with an HTML5 time element. The full time is present in ISO8601 format, with the timezone offset for your site, and inside the tag is the human readable one.
<time datetime="2016-06-22T23:52:09-04:00">June 22, 2016</time>
You get two times per post..the published time and the updated time. Many themes have the updated time visually hidden, but available for parsing. If you do not have a fully formatted timestamp in datetime, you should do so. Positively, since WordPress 5.3, the offset is properly set based on your site settings, where previously you had to edit the theme to get this. The displayed time is up to you.
Add class="dt-published"
to the publish time of the post, and class="dt-updated"
to the updated/modified time of the post.
We also, most importantly, want to make sure the author is marked up correctly. That should include, at minimum, the author’s name, if not URL and photo. All author properties should be surrounded by an element that has class="p-author h-card"
. The photo should have class="u-photo"
, indicating it is a representative photo of the element it is inside…the h-card. H-cards represent people, organizations, or places. By adding the p-author, we indicate that this person is the author of the piece. The p- tells the parser that whatever text is inside here is the value of the author property. You can also add a url for the author website, marking it class="u-url"
which states it is the URL that represents the containing element…the h-card/author property.
Here is a simplified example of what this might look like…
<div class="h-entry"> <time class="dt-published" datetime="2016-06-22T23:52:09-04:00">June 22, 2016</time> <span class="p-author h-card"><a class="u-url" href="https://joebloggs.com">Joe Bloggs</a><img class="u-photo" src="https://joebloggs.com/avatar.jpg" /></span> </div>
So, if we run the new file through a Microformats parser(I like php.microformats.io), we’d get a nice output…
{ "type": [ "h-entry" ], "properties": { "url": [ "https://joebloggs.com" ], "published": [ "2016-06-22T23:52:09-04:00" ], "author": [ { "type": [ "h-card" ], "properties": { "photo": [ "https://joebloggs.com/avatar.jpg" ], "name": [ "Joe Bloggs" ] }, "value": "Joe Bloggs" } ] } }
Looks pretty good…except no content… Content is a bit more complicated, because WordPress stores content in the database, but when outputting it, puts it through a filter called “the_content”, which many plugins use to add things that aren’t content to the post.
Content is supposed to be wrapped in an element with the class="e-content"
. If we wrap the output of the_content, we might incorporate things from other plugins.
While it is by no means the most reliable way, my solution is to use the same content filter, but at the first priority, wrapping what original came out of post_content before all the other items.
You can do the same with the summary, if it exists, wrapping it in p-summary.
function add_econtent( $content ) { // Do Not Add this is it is a Feed. if ( is_feed() ) { return $content; } $wrap = '<div class="e-content">'; // If there is no content, do not bother. if ( empty( $content ) ) { return $content; } return $wrap . $content . '</div>'; } add_filter( 'the_content', 'add_econtent', 1 ); function add_psummary( $excerpt ) { // Do Not Add this is it is a Feed. if ( is_feed() ) { return $excerpt; } $wrap = '<div class="p-summary">'; // If there is no excerpt, do not bother. if ( empty( $excerpt ) ) { return $excerpt; } return $wrap . $excerpt . '</div>'; } add_filter( 'the_excerpt', 'add_psummary', 1 );
In the next part, we’ll dive even more into the weeds, talking about other classic microformats and rel-values and what to do with them. Probably before 2024.