Use in_the_loop() instead of checking global post IDs. Confirmed works with patched theme.