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
- Download phpexec.txt
- Rename phpexec.txt to phpexec.php
- Upload it to the
/wp-content/plugins/
directory - 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
- Download the plugin.
- Rename execphp.txt to execphp.php
- Upload it to the
/wp-content/plugins/
directory - 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.