It is possible to run a custom PHP script or function in WordPress posts and pages. The best approach is to use a PHP code inserter plugin. There are several plugins available for free at the WordPress repository that you can use to insert PHP scripts, but we prefer Insert PHP Code Snippet by xyzscripts because it is lightweight.
Solution Steps
- Go to tour WordPress dashboard under plugins and click add new plugin
- Install and activate a plugin developed by xyzscripts called Insert PHP Code Snippet
- Create code by adding your custom code to the form
- Once you have created code a shortcode will be generated
- Add the shortcode to your pages or posts and click update or publish.
- The script will be executed
Another alternative of PHP code inserter plugin is Woody code snippets.