Insert PHP code In WordPress Page and Post

WordPress does not execute PHP in post/page content by default unless it has a shortcode.

The quickest and easiest way to do this is to use a plugin that allows you to run PHP embedded in post content.

There are two other “quick and easy” ways to accomplish it without a plugin:

  • Make it a shortcode (put it in functions.php and have it echo the country name) which is very easy – see here: Shortcode API at WP Codex

  • Put it in a template file – make a custom template for that page based on your default page template and add the PHP into the template file rather than the post content: Custom Page Templates

Leave a Comment