Categories
Meta Websites

Fixing microformat support on Twenty Twenty WordPress theme

Two microformat elements are missing on posts in the WordPress theme Twenty Twenty, but can be fixed with a quick edit. The missing microformats tell people following your posts what date the post was published and what the permalink URL is to access the post. Including this markup in your posts is helpful to let others follow your posts.

Unfortunately, the way the Twenty Twenty theme is set up, this change cannot be made to the child theme, but must be made to the parent theme itself. That means I will need to make it again each time I update the theme.

Using WordPress’s Theme Editor, with the parent theme selected, open the folder ‘inc,’ then the file template-tags.php.

Replace line 400 (Twenty Twenty as of 2024 April — original line reads: <a href=”<?php the_permalink(); ?>”><?php the_time( get_option( ‘date_format’ ) ); ?></a>) with:

<a class="u-url" href="<?php the_permalink(); ?>"><?php printf( '<time class="dt-published" datetime="%1$s">%2$s</time>', get_the_date( DATE_W3C ), get_the_date( get_option( 'date_format' ) ) ); ?></a>

This adds the microformat markup “u-url” to the permalink and “dt-published” to the permalink / date posted.

Thanks David and Angelo for helping me troubleshoot 😊

ADDED 10/22:

There are another couple additional microformats missing from posts: the title and content tags. Both these can be addressed by simple additions to template files.

In the folder template-parts, in the file ‘entry-header.php’, you can fix the title microformat by adding ‘p-name’ as a class to the h1 in lines 46 and 48:

if ( is_singular() ) {
the_title( '<h1 class="p-name entry-title">', '</h1>' );
} else {
the_title( '<h2 class="p-name entry-title heading-size-1"><a href="' . esc_url( get_permalink() ) . '">', '</a></h2>' );
}

In the same folder, in the file ‘content.php’, you can tag the content of the post by adding ‘e-content’ to the div identifying the content of the post in line 30:

<div class="entry-content e-content">

By Tracy Durnell

Writer and designer in the Seattle area. Reach me at tracy.durnell@gmail.com. She/her.

3 replies on “Fixing microformat support on Twenty Twenty WordPress theme”

Leave a Reply