ProThemesWP PHP Shortcode

The easiest way to add php to your posts is to install ProThemesWP PHP Shortcode plugin and then use its [php] shortcode.

Here is a very simple example using the [php] shortcode. The source code for the example is below the example.

This website is called ProThemesWP

[php]
//The name of this website
echo '<p>This website is called "' . get_bloginfo( 'name' ) . '"</p>';

Here is a complex example that shows the php reading data entered in a form.

[php]
//Create a form that submits its data to this post
echo '<form action="' . get_the_permalink() . '" method="POST">
<p><label for="text-value">Please enter a value and click submit to see the php working:</label>
<input type="text" name="text-value" id="text-value" />
</p>
<p><input type="submit" value="Submit" /></p>
</form>';
//If the form has been submitted then display the text value that was entered.
if( isset( $_POST['text-value' ] ) ) :
   echo '<p>The text value you entered was "' . esc_html( $_POST['text-value'] ) . '"</p>'; 
endif;
[/php]

Summary

PHP can be placed inline in posts, pages and custom post types by installing ProThemesWP PHP Shortcode and using the shortcode [php].