⬅ See all messages


Jeremy Herve
Jeremy Herve

WordPress, TV Series, music, kids, and board games. I think that’s probably the best way to define me in a few words. 🙂

I work at Automattic where I lead a team building tools for bloggers and creators. I talk a lot about WordPress things, but also about all things open source in general.

I post in English and in French.

I live in Brittany, France, so you’ll also find me sharing pictures from our beautiful region from time to time.

1,244 posts
196 followers

Quick tip if you use the ActivityPub plugin on your WordPress site, and if you write in multiple languages on your site. Use the activitypub_locale filter to make sure your posts on the Fediverse are set to the locale matching the post on your site.

/**
 * Set a post's language in its ActivityPub representation
 * based on post tags.
 * The post tags must match an array of language codes you use on your site (in my example, English, Hungarian, and French).
 * When no tags are found, the post's language uses the default (the blog's language).
 *
 * @param string  $lang    The locale of the post.
 * @param WP_Post $post    The post object.
 *
 * @return string The filtered locale of the post.
 */
function jeherve_custom_ap_language( $lang, $post ) {
	if ( ! $post instanceof WP_Post ) {
		return $lang;
	}

	// Get the post's hashtags.
	$post_tags = get_the_tags( $post->id );

	if ( ! empty( $post_tags ) ) {
		// Is there a "en, "hu", or "fr" tag?
		foreach ( $post_tags as $tag ) {
			if ( in_array( $tag->slug, array( 'en', 'fr', 'hu' ), true ) ) {
				$lang = $tag->slug;
				break;
			}
		}
	}

	return $lang;
}
add_filter( 'activitypub_locale', 'jeherve_custom_ap_language', 10, 2 );

This way, I can add the tag to this post, and ensure the post will be shown as an English-language post for folks on the Fediverse.

This is important for folks who filter posts per language on the Fediverse, or who use translation tools to automatically translate posts in foreign languages.

Reactions on the Fediverse and on the ATmosphere

  1. Jeremy Herve Avatar

    If that code snippet doesn’t look too readable on your Fediverse client, be sure to visit the original post, that should help!



Jeremy Herve
Jeremy Herve

WordPress, TV Series, music, kids, and board games. I think that’s probably the best way to define me in a few words. 🙂

I work at Automattic where I lead a team building tools for bloggers and creators. I talk a lot about WordPress things, but also about all things open source in general.

I post in English and in French.

I live in Brittany, France, so you’ll also find me sharing pictures from our beautiful region from time to time.

1,244 posts
196 followers