Remove Buttons from the Visual Editor

Unnecessary buttons in the Visual Editor? Try this

add_filter('mce_buttons', 'remove_mce_buttons' );
function remove_mce_buttons($buttons) {
	unset($buttons[16]);
	return $buttons;
}
//     [0] => bold
//     [1] => italic
//     [2] => strikethrough
//     [3] => |
//     [4] => bullist
//     [5] => numlist
//     [6] => blockquote
//     [7] => |
//     [8] => justifyleft
//     [9] => justifycenter
//     [10] => justifyright
//     [11] => |
//     [12] => link
//     [13] => unlink
//     [14] => wp_more
//     [15] => |
//     [16] => spellchecker
//     [17] => fullscreen
//     [18] => wp_adv

If you’re concerned about accidentally removing the wrong one, it’s simple enough to add a check

add_filter('mce_buttons', 'remove_mce_buttons' );
function remove_mce_buttons($buttons) {
	if ($buttons[16] == 'spellchecker')
	unset($buttons[16]);
	return $buttons;
}

Change Admin Footer Text

If you need to customize the WordPress administration area, you’ll find this useful.

add_filter('admin_footer_text', 'left_admin_footer_text_output'); //left side
function left_admin_footer_text_output($text) {
    $text = 'How much wood would a woodchuck chuck?';
    return $text;
}

add_filter('update_footer', 'right_admin_footer_text_output', 11); //right side
function right_admin_footer_text_output($text) {
    $text = "That's purely hypothetical.";
    return $text;
}

Custom Post Types

Adding a new post type, for when ‘posts’ and ‘pages’ just won’t do.

add_action( 'init', 'my_new_post_types' );
function my_new_post_types() {
    $labels = array(
        'name' => _x('Hotels', 'post type general name'),
        'singular_name' => _x('Hotel', 'post type singular name'),
        'add_new' => _x('Add New', 'hotel'),
        'add_new_item' => __('Add New Hotel'),
        'edit_item' => __('Edit Hotel'),
        'new_item' => __('New Hotel'),
        'view_item' => __('View Hotel'),
        'search_items' => __('Search Hotels'),
        'not_found' =>  __('No hotels found'),
        'not_found_in_trash' => __('No hotels found in Trash'), 
        'parent_item_colon' => '',
        'menu_name' => 'Hotels'    
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'show_in_menu' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => true, 
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','author','thumbnail','excerpt','comments')
    ); 
    register_post_type('hotel',$args);
}

Hide Plugin Update count

In case you need to hide the plugin update count (can’t/don’t want to update yet) you can hide it with this. Can be especially useful if you don’t want clients to wander over the the update area.

add_action('admin_menu', 'remove_plugin_update_count');
function remove_plugin_update_count(){
    global $menu, $submenu;
    $menu[65][0] = 'Plugins';
    $submenu['index.php'][10][0] = 'Updates';
}

Remove Title Attribute from Featured Image

If you have featured images (formerly post thumbnails) that aren’t named as well as they could be, it’s nice to remove the title attribute so that things like “header-large” don’t appear in the tool tips.

add_filter('post_thumbnail_html', 'remove_feat_img_title');
function remove_feat_img_title($img) {
    $img = preg_replace('/title="(.*?)"/','',$img);
    return $img; 
}

Custom Taxonomies

When you need more than just ‘categories’ and ‘tags’ use custom taxonomies.

Especially useful in combination with custom post types.

add_action('init', 'my_new_taxonomies');
function my_new_taxonomies() {

	$labels = array(
	'name' => __( 'Action Hooks' ),
	'singular_name' => __( 'Action Hook' ),
	'search_items' =>  __( 'Search Action Hooks' ),
	'popular_items' => __( 'Popular Action Hooks' ),
	'all_items' => __( 'All Action Hooks' ),
	'parent_item' => null,
	'parent_item_colon' => null,
	'edit_item' => __( 'Edit Action Hook' ),
	'update_item' => __( 'Update Action Hook' ),
	'add_new_item' => __( 'Add New Action Hook' ),
	'new_item_name' => __( 'New Action Hook' ),
	'separate_items_with_commas' => __( 'Separate hooks with commas' ),
	'add_or_remove_items' => __( 'Add or remove hooks' ),
	'choose_from_most_used' => __( 'Choose from the most used hooks' ),
	'menu_name' => __( 'Action Hooks' ),
	); 

	register_taxonomy('action_hook','post',array(
	'hierarchical' => false,
	'labels' => $labels,
	'show_ui' => true,
	'query_var' => true,
	'rewrite' => array( 'slug' => 'action_hook' ),
	));
}

My FreeNAS Box

I wasn’t planning on building a computer last week, but I made the mistake of browsing NewEgg while also thinking it would be neat to have some sort of home server for easily sharing files. So here I am, less than 1 week from clicking the first “Add to Cart” button, with my FreeNAS box.

I hope most of you are smarter than I am and won’t need any of this info, but here it is anyway. Continue reading My FreeNAS Box

Fetch the User-Agent String and Save as User Meta

Some times a client will complain that their site doesn’t look right or something equally as vague. Inevitable we ask “What browser are you using?” but getting the answer can be tricky. So, let’s just automatically get their user-agent and save it where we can access it.

Granted, this isn’t perfect. The client could have just logged in from someone else’s computer, and it is possible to fake the user-agent… but I’m counting on this being rare.

Continue reading Fetch the User-Agent String and Save as User Meta

Including Custom Fields Inside Your Post

WordPress/TinyMCE will sometimes remove code that you’d rather it not. For example, have you have tried to add a Google Map to a post without the aid of a plugin? You can’t. The iframes aren’t allowed.

Because of this, and a few other similar instances, I wrote a plugin that would let me easily bypass this filters. Continue reading Including Custom Fields Inside Your Post