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;
}

Hide Menu Items

If you need to hide menus from the sidebar of the administration area, you can use this. Keep in mind, this method does not block access, just hides the link.

add_action('admin_menu', 'hide_menu_links');
function hide_menu_links(){
  	global $menu,$submenu;

  	if ($submenu['plugins.php'][15][0] == 'Editor')
	unset($submenu['plugins.php'][15]);

  	if ($menu[15][0] == 'Links')
	unset($menu[15]);

}
// $menu
//     [2] => {Dashboard}
//     [4] => {separator}
//     [5] => {Posts}
//     [10] => {Media}
//     [15] => {Links}
//     [20] => {Pages}
//     [25] => {Comments}
//     [59] => {separator}
//     [60] => {Appearance
//     [65] => {Plugins}
//     [70] => {Users}
//     [75] => {Tools}
//     [80] => {Settings}
//     [99] => {separator}

// $submenu
//     [index.php] =>
//         [0] => {Dashboard}
//         [10] => {Updates}
//     
//     [edit.php] =>
//         [5] => {Posts}
//         [10] => {Add New}
//         [15] => {Categories}
//         [16] => {Post Tags}
//     
//     [upload.php] =>
//         [5] => {Library}
//         [10] => {Add New}
//     
//     [link-manager.php] =>
//         [5] => {Links}
//         [10] => {Add New}
//         [15] => {Link Categories}
//     
//     [edit.php?post_type=page] =>
//         [5] => {Pages}
//         [10] => {Add New}
//     
//     [themes.php] =>
//         [5] => {Themes}
//         [7] => {Widgets}
//         [10] => {Menus}
//     
//     [plugins.php] =>
//         [5] => {Plugins}
//         [10] => {Add New}
//         [15] => {Editor}
//     
//     [users.php] =>
//         [5] => {Users}
//         [10] => {Add New}
//         [15] => {Your Profile
//     
//     [tools.php] =>
//         [5] => {Tools}
//         [10] => {Import}
//         [15] => {Export}
//     
//     [options-general.php] =>
//         [10] => {General}
//         [15] => {Writing}
//         [20] => {Reading}
//         [25] => {Discussions}
//         [30] => {Media}
//         [35] => {Privacy}
//         [40] => {Permalinks}

Simple “Upcoming Posts” Widget

Here’s a simple widget for displaying upcoming posts. Title of widget and number of posts shown is configurable.

add_action( 'widgets_init', 'upcoming_posts_widget_load_widget' ); /* Add our function to the widgets_init hook. */
function upcoming_posts_widget_load_widget() { register_widget( 'upcoming_posts_widget' ); } /* Function that registers our widget. */

class upcoming_posts_widget extends WP_Widget {

    function upcoming_posts_widget() {
        $widget_ops = array( 'classname' => 'upcoming_posts', 'description' => 'Upcoming Posts Widget' ); /* Widget settings. */
        $control_ops = array(  'id_base' => 'upcoming_posts' ); /* Widget control settings. */
        $this->WP_Widget( 'upcoming_posts', 'Upcoming Posts Widget', $widget_ops, $control_ops ); /* Create the widget. */
    }

    function widget( $args, $instance ) {
        extract( $args );  /* before/after widget, before/after title (defined by themes). */
        extract($instance);

        echo $before_widget;
        echo $before_title . $title . $after_title; 

        echo '<ul>';
        $posts = get_posts("post_status=future&numberposts=$numberposts&order=ASC");
        $posts = array_reverse($posts);
        foreach ($posts as $p) {
            echo '<li>'. $p->post_title .'</li>';
        }
        echo '</ul>';
        echo $after_widget; 
    }

    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $instance['title'] = strip_tags( $new_instance['title'] );
        $instance['numberposts'] = (int) $new_instance['numberposts'];
        return $instance;
    }

    function form( $instance ) {
        $defaults = array( 'title' => 'Upcoming Posts', 'numberposts' => 3 );
        $instance = wp_parse_args( (array) $instance, $defaults );
    ?>
        <p>
            <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
            </select>
        </p>
        <p>
            <label for="<?php echo $this->get_field_id( 'numberposts' ); ?>">Number Posts:</label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'numberposts' ); ?>" name="<?php echo $this->get_field_name( 'numberposts' ); ?>" value="<?php echo $instance['numberposts']; ?>" />
            </select>
        </p>
    <?php
    }
}