Post format plural strings

One thing that bothers me a bit about post formats is that there’s no plural version of the post format names, especially since I was already using the “asides” and “galleries” tags before post formats came on the scene.

Typically, when I tag or categorize something, I like to go with the plural version over the singular version of the word when it makes sense. For example, this blog post will be tagged “WordPress Tutorials” rather than “WordPress Tutorial.” However, I’ll also tag this article “WordPress” because “WordPresses” doesn’t work. So, it’s a bit more than just about singular vs. plural. It’s about a feeling for the terminology.

This is one of those odd preferences of mine. I decided to make my post format archive titles plural. In other places, the singular version of the word works well.

The code

You can place the following code in your theme’s functions.php file or, preferrably, a custom functions plugin.

/* Filter the post format archive title. */
add_filter( 'single_term_title', 'my_post_format_single_term_title' );

/**
 * Filters the single post format title, which is used on the term archive page. The purpose of this
 * function is to replace the singular name with a plural version.
 *
 * @author Justin Tadlock <justin@justintadlock.com>
 * @copyright Copyright (c) 2012
 * @link /archives/2012/09/07/post-format-plural-strings
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * @since 0.1.0
 * @access public
 * @param string $title The term name.
 * @return string
 */
function my_post_format_single_term_title( $title ) {

	if ( is_tax( 'post_format' ) ) {
		$term = get_queried_object();
		$plural = my_post_format_get_plural_string( $term->slug );
		$title = !empty( $plural ) ? $plural : $title;
	}

	return $title;
}

/**
 * Gets the plural version of a post format name.
 *
 * @author Justin Tadlock <justin@justintadlock.com>
 * @copyright Copyright (c) 2012
 * @link /archives/2012/09/07/post-format-plural-strings
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * @since 0.1.0
 * @access public
 * @param string $slug The term slug.
 * @return string
 */
function my_post_format_get_plural_string( $slug ) {

	$strings = my_post_format_get_plural_strings();

	$slug = str_replace( 'post-format-', '', $slug );

	return isset( $strings[ $slug ] ) ? $strings[ $slug ] : '';
}

/**
 * Defines plural versions of the post format names since WordPress only provides a singular version
 * of each format. Basically, I hate having archive pages labeled with the singular name, so this is
 * what I created to take care of that problem.
 *
 * @author Justin Tadlock <justin@justintadlock.com>
 * @copyright Copyright (c) 2012
 * @link /archives/2012/09/07/post-format-plural-strings
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * @since 0.1.0
 * @access public
 * @return array
 */
function my_post_format_get_plural_strings() {

	$strings = array(
	//	'standard' => __( 'Articles',       'my-textdomain' ), // Would this ever be used?
		'aside'    => __( 'Asides',         'my-textdomain' ),
		'audio'    => __( 'Audio',          'my-textdomain' ), // Leave as "Audio"?
		'chat'     => __( 'Chats',          'my-textdomain' ),
		'image'    => __( 'Images',         'my-textdomain' ),
		'gallery'  => __( 'Galleries',      'my-textdomain' ),
		'link'     => __( 'Links',          'my-textdomain' ),
		'quote'    => __( 'Quotes',         'my-textdomain' ), // Use "Quotations"?
		'status'   => __( 'Status Updates', 'my-textdomain' ),
		'video'    => __( 'Videos',         'my-textdomain' ),
	);

	return apply_filters( 'my_post_format_plural_strings', $strings );
}

You’ll notice that I left “Audio” the same. “Audios” just doesn’t feel right to me. I could also see using “Audio Clips” or “Audio Files” as valid alternatives.

Using the code

You may be thinking that the above code is a bit much for post format archive titles. Yes, that’s true. It can be simplified if you want to break it down into a single function. However, I wrote the code so that it’d give you some options for using the plural strings.

The following example gets the plural version of “aside”.

$aside_plural = my_post_format_get_plural_string( 'aside' );

The next example loops through each of the plural strings and echoes them:

foreach ( my_post_format_get_plural_strings() as $string )
	echo $string . '&lt;br />';

There’s plenty you can do with the code, especially if you like to nit-pick about things such as this.