As another poster pointed out, this is almost always a bad idea for security reasons. If you insist on doing it this is how. Since you are using a custom field that can have both php and html, your best bet is to use a shortcode. Something like this will work:
In the file that holds your functions:
function wpsc_do_php($atts, $content){
/*Do some basic validation of the $content field
*to ensure that it is valid php code and that it
*is only using functions that you allow.
*/
return eval($content);
}
add_shortcode('php','wpsc_do_php');
In your custom field, anywhere you want to do php, wrap it in [php][/php]
instead of <?php...?>
, like this:
<html>
<p>Some html formated text with some php content like [php]date('Y-m-d')[/php]</p>
</html>
Then in your theme (or wherever you want to display your custom field), use this code:
echo do_shortcode($my_custom_field_contents);
Again, while this should work, it is a bad idea.