I found the EXEC PHP wordpress plguin while trying to figure out how to execute PHP code inside a wordpress post and page. It works, but do note that you’ll need to make a few settings changes so that your php code will be recognized as php tags and executed.
After installing the EXEC PHP plugin:
1. When writing a wordpress post or page, and you want some PHP code in it, always choose to write in HTML, not in Visual.
2. Under Dashboard > Settings > Writing, disable/uncheck WordPress should correct invalidly nested XHTML automatically”
3. That’s it. You can include your php logic <?php // do your thing here; ?> anywhere in your post, page, sidebar or widget.