Add A Security Question to the Register Screen

Want to allow people to register on your site, but don’t want to be flooded with spam users? Try this:

add_action( 'register_form', 'add_register_field' );
function add_register_field() { ?>
	<p>
		<label><?php _e('What is the name of the ship in the TV show Firefly?') ?><br />
		<input type="text" name="user_proof" id="user_proof" class="input" size="25" tabindex="20" /></label>
	</p>
<?php }

add_action( 'register_post', 'add_register_field_validate', 10, 3 );
function add_register_field_validate( $sanitized_user_login, $user_email, $errors) {
	if (!isset($_POST[ 'user_proof' ]) || empty($_POST[ 'user_proof' ])) {
		return $errors->add( 'proofempty', '<strong>ERROR</strong>: You did not answer the proof-of-humanship question.'  );
	} elseif ( strtolower( $_POST[ 'user_proof' ] ) != 'serenity' ) {
		return $errors->add( 'prooffail', '<strong>ERROR</strong>: You did not answer the proof-of-humanship question correctly.'  );
	}
}

This adds an extra box to the register screen with the question “What is the name of the ship in the TV show Firefly?” The user-provided answer is then compared to the official answer. If correct, the user is registered, otherwise WordPress-friendly error(s) are returned.

Add Featured Image Thumbnail to Posts Page

Customize the information that is displayed on the ‘posts’ page

Adding a column labeled “Thumbnail” (and delete the “Comments” column).

add_filter( 'manage_edit-post_columns', 'set_columns' );
function set_columns($columns) {
	$columns['thumbnail'] = 'Thumbnail';
	unset( $columns['comments'] );
	return $columns;
}

Now we need to tell WordPress what to do with this new “Thumbnail” space. Here, we’re checking for the existence of a featured image and displaying it, or noting that there is no thumbnail.

add_action( 'manage_posts_custom_column', 'fill_columns' );
function fill_columns($column) {
	global $post;
	switch($column) {
		case 'thumbnail' :
			if (has_post_thumbnail($post->ID))
				echo get_the_post_thumbnail($post->ID, array(50, 50));
			else
				echo '<em>no thumbnail</em>';
		break;
	}
}

Customize the Favorites Menu

Ever use that favorites menu up by the “Howdy” greeting? I never really did until I started customizing the options.

One of my favorites is adding a link to the master options page (wp-admin/options.php)

add_filter('favorite_actions', 'custom_favorites');
function custom_favorites($actions) {
		$actions['options.php'] = array('All Settings', 'unfiltered_html'); // this line adds an item
		return $actions;
}

Or, remove the menu entirely

add_filter('favorite_actions', 'remove_favorites');
function remove_favorites($actions) {
		$actions = array(); 
		return $actions;
}

Add More Date/Time Format Options

If you find that you need to offer some non-standard date or time formats to the general settings page, this will help.

add_filter('date_formats', 'add_date_format');
function add_date_format($original) {
        $more = array('D, M jS, Y');
        return array_merge($original, $more);
                        
}

add_filter('time_formats', 'add_time_format');
function add_time_format($original) {
        $more = array('H:i:s a');
        return array_merge($original, $more);
                        
}

Remove “Generator” Tags

Don’t want those “generator” tags in your source? Add this

remove_action( 'wp_head', 'wp_generator' );

To modify the output, you can run in through a filter. In this case, the modification is removal.

add_filter('the_generator', 'remove_generated_by');
function remove_generated_by($footer_text) {
    return '';
}

If you want to be more specific about where the generator tags are are removed, you can change the filter to something like on of these

add_filter('get_the_generator_xhtml', 'remove_generated_by');

Just swap ‘xhtml’ for one of the following as needed: html, xhtml, atom, rss2, rdf, comment, export.

Change Block Format Dropdown in the Visual Editor

Have clients that insist on using <h1> tags throughout their posts? Can’t remember the last time you used the <address> tag? This can help you clean up that block format dropdown menu.

add_filter('tiny_mce_before_init', 'change_mce_dropdown' );
function change_mce_dropdown( $initArray ) {
	$initArray['theme_advanced_blockformats'] = 'p,h3,h4,h5,h6,pre';
	return $initArray;
}