i am engaged on a WordPress plugin and i am attempting to show/get the publish thumbnail under the publish on my “Associated posts” half. I attempted many issues that are purported to work however not for me … right here is the code (on my plugin.php file):
add_theme_support( 'post-thumbnails', array( 'publish', 'web page' ) );
if ( has_post_thumbnail() ) {
echo ('there's a thumbnail');
echo get_the_post_thumbnail(get_the_ID(), "thumbnail"); // nothing
echo get_the_post_thumbnail(); // nothing
echo var_dump(get_the_post_thumbnail(get_the_ID(), "thumbnail")); //string '' (size=0)
echo var_dump(get_the_post_thumbnail()); //string '' (size=0)
the_post_thumbnail('thumbnail'); // nothing
the_post_thumbnail(); // nothing
}
else {
echo ('there is no such thing as a thumbnail');
}
first i assumed that there have been no thumbnail for my publish however my first echo returned “there’s a thumbnail” and all the remaining does not return something … so i do not perceive… what’s lacking ?
Thanks
Edit:
right here is the present full code in my plugin.php file:
operate Similar_Article ($content material) {
if (is_single() || is_page()) {
the_post();
$similar_to_add = '';
$id = get_the_ID();
$content_and_similar = $content material . '<br><br>'; //areas between publish and associated posts
/* many strategies referred to as to search out my associated posts */
if (has_post_thumbnail()){
$content_and_similar .= get_the_post_thumbnail(); // it really works
}
else {
$imageData = wp_get_attachment_image_src(get_post_thumbnail_id ( $id ), 'thumbnail');
$content_and_similar .= '<img src=" '.$imageData[0].' ">';
}
$content_and_similar .= $similar_to_add;
return $content_and_similar;
}
else {
return $content material;
}
}
add_filter( 'the_content', 'Similar_Article' );
my operate works if there’s a thumbnail however show nothing if there is no such thing as a thumbnail…