Php error "Undefined variable:post" when using "get_post_thumbnail_id($post->ID)" Php error "Undefined variable:post" when using "get_post_thumbnail_id($post->ID)" wordpress wordpress

Php error "Undefined variable:post" when using "get_post_thumbnail_id($post->ID)"


My guess would be that this code is in a function, like so:

function doSomething($someparams) {     // ...     $fotoer_recent_thumb = // .....     // ...}

In this case, $post does not exist in this scope, and must be imported by adding the following line inside your function:

global $post;

Alternatively, and more cleanly, pass it as a parameter.


Try this way:

if (has_post_thumbnail()) {     $footer_recent_thumb = wp_get_attachment_image_src(         get_post_thumbnail_id(get_the_ID()) , 'footer-recent-thumbnail'    );    // Do more stuff}