I have added a custom textarea to my featured image only to post, Using the following code.
function add_featured_description( $content ) {
global $post;
$small_description = get_post_meta( $post->ID,'thumbnail_description', true ) !== '0' ? get_post_meta( $post->ID,'thumbnail_description', true ) : '';
global $pagenow;
if (is_admin() && ($pagenow == 'post-new.php' || $pagenow == 'post.php') && ( get_post_type()=='post' ) ) {
return $content .= '<div id="thumb_desc_container">
<textarea name="thumbnail_description" id="thumbnail_description" rows="4" style="width:100%;">'.$small_description.'</textarea>
<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">Enter the image description.</p>
</div>';
} else{
return $content;
}
}
add_filter( 'admin_post_thumbnail_html', 'add_featured_description');
It works fine!!! This code shows the extra textarea only in POST. But when i selected a featured image else
part is executed(only featured image is returned).
When adding an image $pagenow
contains admin-ajax.php
and get_post_type()
is null. global variables $post
produces a null value. What should i do now?