Simple Filters Make Using Custom Post Types Easier

I’m always looking for good ways to make the WordPress UI as intuitive as possible for Manifest Creative clients. You’d be amazed at how many folks get frustrated trying to remember “What field does what?”. There’s naturally a bit of disconnect between filling out information in the admin and how it’s displayed on the front-end to visitors.

A great example of this disconnect between the admin and front-end is one of our non-profit clients. We use a custom post to display a list of sponsors for the organization. Each post type includes several meta fields for details and is displayed on the front-end alongside the sponsor’s logo. In this use case it makes perfect sense that WordPress’ featured image feature would be used for the sponsor’s logo. But, because “featured image” is not immediately equated with a logo, it’s a prime candidate for customization.

By simply changing the text from “Set featured image” to “Choose sponsor logo” we can eliminate any question of where the admin user should set that particular item. As they say, it’s the little things!

When I create a new custom post type, there are 3 areas that I consider mandatory to customize:

  1. The “Enter Title Here” text shown for the post headline
  2. The “Featured Image” meta box title
  3. The link that says “Add featured image” or “Remove featured image”.

All of this code usually goes into the individual PHP file I use to create the custom post type, but you could just as easily include it in your theme’s functions.php file.

<?php
/**
* Filter the default title
*
* @param string $post_title The current 'Enter title here' text
* @return string The modified default text
*/
add_filter('enter_title_here', 'post_type_default_title');
function post_type_default_title($title) {
	global $post_type;
	if ( $post_type == 'mcrm_contacts' ) {
		$title = 'Company Name';
	}
	return $title;
}

/**
* Filter the Featured Image Metabox
*/
add_action('do_meta_boxes', 'post_type_featured_image_box');
function post_type_featured_image_box()
{
    remove_meta_box( 'postimagediv', 'mcrm_contacts', 'side' );
    add_meta_box('postimagediv', __('Company Logo'), 'post_thumbnail_meta_box', 'mcrm_contacts', 'side', 'default');
}

/**
* Filter the Featured Image link
*
* @param string $content The original link for featured image
* @return string The modified string
*/
add_filter('admin_post_thumbnail_html', 'post_type_featured_image_link');
function post_type_featured_image_link( $content ) {
	global $post_type;
  if ($post_type == 'mcrm_contacts') {
    $content = str_replace(__('featured image'), __('logo'), $content);
  }
  return $content;
}
?>