Skip to content

Enjoy Kaizen

Dads’ Breakfast: Commit c6ac2d562b

From the Making of Dads’ Breakfast

HTTPS://CJWILLCOCK.CA/DADS-BREAKFAST-MAKING-OF/

I added microformats to Dads’ Breakfast, my active WordPress theme and ongoing bit of coding in the open.

Dads’ Breakfast: Commit c6ac2d562b,

It is early days in D. B. but my Psymantic theme is longer in the tooth (practice) and in it I wrote some code to mute WordPress’ microformatting with h-entry and hentry wherever post_class() is used. WordPress applies the h-entry context to all of my owned content, sans-theme. A dirty press is, the working press. I think I may have leveled-up on the distraction-free writing mode with this one.

With that out of the way and on adding the h-entry back I was left with a divot to fix when the post_class('h-entry') no longer worked as the WordPress documentation of this library function describes it to do and thus I discovered the platform is left compromised by my D. B. theme architecture. First, I had this planned and second, they-all started it.

Using the conventional post_class() template tag, to now allow a theme author to use discretion on the location of an h-entry via post_class() is a must-do in order to obviate the shoe-horning I need to accomplish to make this theme. h-entry is therefore written wp-entry in the post_class() library function call using a Psymantic-based theme in WordPress.

This is the simplest I can figure to satisfy the requirements of semantic interoperability given modern definitions of both WordPress & Microformats. There is much more done in the Psymantic theme to mute microformatting. Aside: I should write about that maybe.

Trial balloon now steady on a string, adding the h-entry back via wp-entry is done:

/**
 * Filter the post_class tag to convert wp encoded microformats.
 *
 * @since 0.1.0
 *
 * @param  array $classes The list of classes.
 * @param  array $class   The class provided to the function at call-time.
 * @param  int   $post_id The ID of the post for which the classes are given.
 * @return array The filtered classes.
 */
function dadsbreakfast_post_class_convert_wp_microformats( $classes, $class, $post_id ) {
	return str_replace(
		array(
			'wp-entry'
		),
		array(
			'h-entry'
		),
		$classes
	);
}
add_filter( 'post_class', 'dadsbreakfast_post_class_convert_wp_microformats', 10, 3 );

The rest of the commit is there for those with additional time and interest.

Leave a Reply

Your email address will not be published. Required fields are marked *