How to Execute PHP in WordPress Posts, Pages, and Widget Sidebar

Are you struggling with how to insert PHP code into a blog post, page, or widget sidebar? This tutorial will guide you through the process.

Executing PHP in WordPress Page/Post

Installation
  1. Download phpexec.txt
  2. Rename phpexec.txt to phpexec.php
  3. Upload it to the /wp-content/plugins/ directory
  4. Activate the plugin from the WordPress administration menu
Usage

To execute PHP code anywhere in your posts or pages, insert <phpcode> before your PHP code and </phpcode> after your PHP code.

<phpcode>
<?php
echo "Current date and time: ";
echo date("l dS of F Y h:i:s A");
?>
</phpcode>
Security

If you manage a blog with multiple users, you can control who can run this plugin. Adjust the settings in your Administration Menu: Options → PHPExec

Executing PHP in WordPress Widget Sidebar

Installation
  1. Download the plugin.
  2. Rename execphp.txt to execphp.php
  3. Upload it to the /wp-content/plugins/ directory
  4. Activate the plugin from the WordPress administration menu
Usage

This plugin works like a normal text widget, but it also allows PHP code execution. You can create up to 9 instances of this widget.

Screenshot showing PHP widget settings in WordPress
WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail