Wordpress post_thumbnail showing at the beginning of the page

Im trying to display some post thumbnails with a plug in that i created, but when i add the code to the page, its display the thumbnails at the beginning of the page before the other things that i have. I donĀ“t know why is that.

The plug in:

<?php
add_image_size( 'cortar', 250, 250, true ); // Hard Crop Mode
function wpb_recent_post() { 
$the_query = new WP_Query( 'showposts=1&cat=25' ); 
while ($the_query -> have_posts()) : $the_query -> the_post();
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), cortar, false, '' );?>
<img src="<?php echo $src[0];?>" />
<?php endwhile;
} 
add_shortcode('posts_recientes', 'wpb_recent_post');
?>

The content of the page:

<h3>Poesia</h3>

[three_columns]
[column1]

<h4>This is a heading</h4>
[posts_recientes]

[/column1]
[column2]

<h4>This is a heading</h4>
[posts_recientes]

[/column2]
[column3]

<h4>This is a heading</h4>
[posts_recientes]

[/column3]
[/three_columns]

The way it displays:

http://www.ixmapp.com/circulodepoesia/prueba/

it should display The headings before the thumbnails.

Any help would be really appreciated.

Solutions

Wordpress executes the function once before the page is loaded, so the output happens at the very beggining.

Try to echo the full img-HTML-tag.

echo '<img src="'.$src[0].'" />';

Thanks eevaa. You are right Wordpress executes the function before the page is loaded. This is how i solved the problem.

<?php
add_image_size( 'cortar', 250, 250, true ); // Hard Crop Mode

function wpb_recent_post() { 
$the_query = new WP_Query( 'showposts=1&cat=25' ); 
while ($the_query -> have_posts()) : $the_query -> the_post();
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), cortar, false, '' );
endwhile;
wp_reset_postdata();
return('<img src=".$src[0]." />');
} 
add_shortcode('posts_recientes', 'wpb_recent_post');
?>

Similar questions

Pages with a loop (index, archive) are loading the first image as post_thumbnail
Using post thumbnails for custom header images -- works fine on straight pages. But custom templates that load a loop (including index) are pulling the first image instead of using the one set in the featured image field. Anyone seen this before? Thanks! -m
How to not show post_thumbnail from specific category for not logged users
Can you guys help me with some examples so i can sort out the thumb posts from a specific category (EXAMPLE) to not be shown for not logged users, instead to be shown an image which tells them that they have to be logged in order to see that post. Logged users can see all thumb posts. I tried to have this question short as possible, if need anythin...
Secondary Featured Image Function (post_thumbnail)
Does anyone know if it is possible to add a secondary Featured image function to the pages and post editor?
WP Insert post with post_thumbnail
Insert post thumbnail with 'wp_insert_post', i'm trying this code but does not work, the field 'get_field('imagem_do_produto') returns the url of the image, why not work? he code creates the post, but only the title or content. I wanted to add a highlighted image for this post to be created. tnks
Assign SQL 'post_thumbnail' column as featured image
I have added a column called post_thumbnail to my wp_posts table. Is there any way I can make post_thumbnail to each post's featured image?
Wanting to change presentation from full post to featured image (post_thumbnail) only
I am working on a blog (http://goo.gl/xazMe0) and this is the code of the index.php: Issue: Instead of showing all the whole posts on the index page, immediately, I want to show only the featured images of the posts and then make these clickable to enter the post with the full content. So, I guess, I have to remove the line and replace it by someth...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.