Quantcast
Channel: Crunchify
Viewing all articles
Browse latest Browse all 1037

How to Show WordPress Featured Image in WordPress Admin Panel

$
0
0

WordPress-Post-Edit-Admin-Area-Show-Thumbnails-Crunchify

As we discussed before – WordPress is completely amazing. With lots of hooks and functions you could achieve literally anything. You could modify WordPress Admin are the way you want, like, modifying list of columns, changing order, removing admin options, hiding Help link, etc.

In this tutorial we will go over simple but for someone very effective way to show thumbnails into WordPress Admin area.

Why do we need Featured Image in  WordPress admin panel?

Last week I moved my site from one domain to another domain. Because of some complexity I lost Featured image for quite a few posts. Now I wanted to have featured image for only those posts.

There are few WordPress plugins also available which fills the featured image with 1st image from post but I didn’t want that. So decided to create script which shows featured image in admin panel if that exist OR just show nothing. So I could manually go to that page/post and add featured image.

Another must read: Setup SSL (HTTPS) correct way

Let’s get started

Step-1

  1. Open WordPress admin panel
  2. Go to Appearance -> Editor
  3. Open functions.php file and put below code

add_image_size( 'crunchify-admin-post-featured-image', 120, 120, false );

// Add the posts and pages columns filter. They can both use the same function.
add_filter('manage_posts_columns', 'crunchify_add_post_admin_thumbnail_column', 2);
add_filter('manage_pages_columns', 'crunchify_add_post_admin_thumbnail_column', 2);

// Add the column
function crunchify_add_post_admin_thumbnail_column($crunchify_columns){
	$crunchify_columns['crunchify_thumb'] = __('Featured Image');
	return $crunchify_columns;
}

// Let's manage Post and Page Admin Panel Columns
add_action('manage_posts_custom_column', 'crunchify_show_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'crunchify_show_post_thumbnail_column', 5, 2);

// Here we are grabbing featured-thumbnail size post thumbnail and displaying it
function crunchify_show_post_thumbnail_column($crunchify_columns, $crunchify_id){
	switch($crunchify_columns){
		case 'crunchify_thumb':
		if( function_exists('the_post_thumbnail') )
			echo the_post_thumbnail( 'crunchify-admin-post-featured-image' );
		else
			echo 'hmm... your theme doesn't support featured image...';
		break;
	}
}

Step-2

  1. Click Update file button
  2. Go to Posts -> All Posts
  3. OR Pages -> All Pages

You should see featured image in Admin Panel. We are using manage_posts_columns and manage_pages_columns WordPress filters and manage_posts_custom_column and manage_pages_custom_column WordPress Actions.

Have something to add to this article? Please chime in and join the conversation below.

The post How to Show WordPress Featured Image in WordPress Admin Panel appeared first on Crunchify.
Author: App Shah

Viewing all articles
Browse latest Browse all 1037

Trending Articles