I'm using get_the_ID()
in footer.php
but it returns a wrong value.
It might come from any of the plugin which is altering The Loop without resetting it after with wp_reset_postdata()
as mentioned in $post->ID and the_id() always return the wrong value.
Indeed the page shows a list of recent posts, etc. so this might modify the current Loop.
If I can't modify this (because of third party code), how to get the ID of the current post in the footer anyway, with PHP?
wp_reset_postdata()
in your footer before theget_the_ID()
?get_the_ID()
should return the correct ID. Now most likely some third party code is not behaving nicely, and with callingwp_reset_postdata()
you simply reset the state to how it should have been. If something breaks, get rid of that what broke (and whatever forgot to reset the postdata).