Add or Change Content in the Featured Image Meta Box

Perhaps you need to provide a little extra instruction about the Featured Image meta box. It doesn’t take much to add your own text to that box:

add_filter( 'admin_post_thumbnail_html', 'add_featured_image_instruction');
function add_featured_image_instruction( $content ) {
    return $content .= '<p>The Featured Image is an image that is chosen as the representative image for Posts or Pages. Click the link above to add or change the image for this post. </p>';
}

Remove Categories Meta Box

Sometimes, the ability to add multiple categories to a single post can cause problems. Or maybe you’re working with custom taxonomies and you need to make sure only one term is assigned to a post. Assuming you’re creating your own alternative category selection box, you can use this to get red of the default meta box.

add_action('admin_init','remove_cat_box');
function remove_cat_box() {
    //args: $categoryslug.'div', $posttype, $location
    remove_meta_box('categorydiv', 'post', 'side');
}

Shortcode with Attributes

For a variety of reasons, you may not be able to add content directly to the WordPress editor. Maybe it’s funky code that’ll get stripped out, or you want a random quote to show up, or it’s some other kind of dynamic content.

That’s what shortcodes are good for! Here’s a simple one that creates a ‘youtube’ shortcode for embedding videos in your post.

add_shortcode( 'youtube', 'youtube_shortcode' );
function youtube_shortcode( $atts ) {
    extract( shortcode_atts( array('id' => '', 'width' => 480, 'height' => 390) , $atts ) );
    $id = trim($id);
    if (empty($id)) return;
    return '<iframe title="YouTube video player" width="'. $width .'" height="'. $height .'" src="http://www.youtube.com/embed/'. $id .'" frameborder="0" allowfullscreen></iframe>';
}

Used in your post like this: [youtube id="a1Y73sPHKxw"]. The width and height attributes will default to 480 and 390 respectively if not specified in the shortcode. Quotes around the attribute value are not required unless your value has a space.

Remove IM Fields From Profile Page

Need to declutter the profile options by removing the various IM fields. It’s easy

add_filter('user_contactmethods', 'remove_im_options', 10, 2); 
function remove_im_options( $user_contactmethods, $user ) {
    unset($user_contactmethods['aim']);
    unset($user_contactmethods['yim']);
    unset($user_contactmethods['jabber']);
    //$user_contactmethods = array();
    return $user_contactmethods;
}

Remove Library Tab from Post-Side Media Pop-Up

I’m working on a plugin right now where I’m having to hide or limit a lot of features depending on the current user’s capabilities. Among those limitations is media uploading and editing access. I’m using this snippet to hide the Media Library tab from the Add an Image pop-up on the edit post page.

add_filter('media_upload_tabs','no_library_tab');
function no_library_tab($tabs) {
    if (!current_user_can('promote_users')) { 
        unset($tabs['library']);
    }
    return $tabs;
}

Prevent Option From Being Updated

If you need to hand over the reins to a client, but want to make sure certain options stay unchanged, you can add this code:

add_filter( 'pre_update_option_admin_email', 'prevent_option_change', 10, 2 ); 
function prevent_option_change( $newvalue, $oldvalue ) {
    return $oldvalue;
}

In this case, I’m preserving ‘admin_email’ – just change that part of the filter hook to preserve another option.

Add Extra Content to the Widgets Admin

I don’t have a good example of why you might want or need this, but nevertheless, if you should want to add additional text to the Widgets admin, it’s pretty darn easy:

add_action( 'widgets_admin_page', 'widgets_admin_info' );
function widgets_admin_info() {
    ?>
    <p style="clear:both;">Hello there!!</p>
    <?php
}