Forked from brunomonteiro3/featured-thumbnail-column.php
Created
October 17, 2015 14:42
-
-
Save thiagoeliasr/bedd5a5cce71552eaa40 to your computer and use it in GitHub Desktop.
Show the featured image from each post on Wordpress dashboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// GET FEATURED IMAGE | |
function ST4_get_featured_image($post_ID) { | |
$post_thumbnail_id = get_post_thumbnail_id($post_ID); | |
if ($post_thumbnail_id) { | |
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'featured_preview'); | |
return $post_thumbnail_img[0]; | |
} | |
} | |
// ADD NEW COLUMN | |
function ST4_columns_head($defaults) { | |
$defaults['featured_image'] = 'Foto principal'; | |
return $defaults; | |
} | |
// SHOW THE FEATURED IMAGE | |
function ST4_columns_content($column_name, $post_ID) { | |
if ($column_name == 'featured_image') { | |
$post_featured_image = ST4_get_featured_image($post_ID); | |
if ($post_featured_image) { | |
echo '<a href="' . admin_url('post.php?post=' . $post_ID . '&action=edit') . '"><img src="' . $post_featured_image . '" /></a>'; | |
} | |
} | |
} | |
add_filter('manage_posts_columns', 'ST4_columns_head'); | |
add_action('manage_posts_custom_column', 'ST4_columns_content', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment