You might want to add PHP code in your pages or posts on a WordPress website, we’ve got you covered. We are going to share one of the easiest methods to add PHP code to your WordPress pages or posts. By the end of this article, you will know how to add PHP code in your WordPress posts or pages.

It is easy to add HTML codes on your WordPress posts or pages as well. Similarly, We are going to share the easiest way to add PHP codes to your WordPress pages or posts. However, there is no direct way to add PHP code from the WordPress settings itself.

Firstly, just to be on a safer side, download a backup of your website. This will ensure that you do not lose any element from your pages or posts while adding PHP code to the same. You can keep this file at the location which is easily accessible on your local storage.

Steps to add PHP Code in your WordPress Post or Page using Plugins

Without wasting your time, here is the easiest method that you can try to add PHP code in your WordPress post or page. By default, WordPress would not allow you to add PHP code to your page/posts. However, Most of the themes & plugins work is done using PHP. In this method, We are going to use a plugin that will help us to add the PHP code in posts/pages.

We are going to use the Insert PHP Code Snippet plugin for this particular use. You can follow the steps and add PHP code to your WordPress posts or pages.

  1. Go to your WordPress Dashboard
  2. Click on Plugins and then click on Add New Plugin
  3. Search for the Insert PHP Code Snippet plugin from the search bar.
  4. Install the plugin and Activate it as well.
  5. Navigate back to your WordPress dashboard.
  6. Click on XYZ PHP Code. Then press PHP Code Snippets.
  7. Under the PHP Code Snippets section, click on Add New PHP Code Snippet.
  8. Write down the PHP code that you would like to see on your pages/posts in the PHP code field. Also, give a tracking name to the code.
  9. Now, Click on Create to Save the PHP code
  10. You will see a success message if the process of saving the code was successful. For the usage of these snippet codes, you need to make sure that they are Active. In order to do so, click on the Action button.
  11. You will see a green pause signal besides the active snippets. And, Checkmark signal for the inactive snippets.
  12. Copy the Shortcode of the PHP code that you want to use. We will have to use it on the page/post.
  13. Now, that you have saved the PHP code & it is active, we need to add it in the post/page. Edit the page/post where you want to add the PHP code.
  14. You just need to paste the shortcode of the PHP code that you want to include in the page/post. Paste the shortcode that we copied previously. If you are using Guttenberg (Block Editor), you can also include a block for the same.
  15. Update the Changes of your page/post. Clear the cache of your page/post & check if you can see the PHP code working.
  16. That’s It. You have successfully added PHP code in your Page/Post on a WordPress website.

You can create as many as PHP Code in the plugin settings. Just make sure that you are using the right shortcode for every PHP snippet that you want to execute. You can use different blocks or simply paste the shortcode directly in the page/post.


That was all about How to add PHP code in your WordPress pages or posts. If you are facing any problems or having any doubts, let us know through the comments. Share your experience while using the method to add PHP code on your WordPress pages/posts.

All you have to do is create the PHP code entries in the plugin settings. Once you activate the PHP code, you can copy the Shortcodes directly to the pages or posts wherever you want.

Have a Nice Day ahead😍!!

Previous ArticleNext Article

Leave a Reply

Your email address will not be published. Required fields are marked *