add PHP code to WordPress posts or pages

How to add PHP code to WordPress posts or pages

Want to add PHP code to WordPress posts or pages. As a result, save money and easily, create your own plugins.  We guarantee, with these quick simple steps, you will be creating plugins in no time.

How to Add PHP Code to WordPress Posts?

Initially, the direct adding of PHP code to WordPress posts or pages is not allowed. However, in WordPress, you can use custom shortcodes to insert  PHP code into posts or pages. You can quickly create a plugin that will enable you to use custom shortcodes anywhere you can type on your site.

Now, I’m only going to show you the basics of creating a plugin. In later posts, I will get more in-depth with WordPress plugins. But, in this post, I’m going to help you make a simple plugin. You can easily edit the plugin right in WordPress. You can also add as many shortcodes to this as your heart desires.

What is a shortcode?

Shortcodes are PHP code designed to perform a specific function or task. Shortcodes appear as text within single brackets. So, insert them anywhere you can paste some text.

So let us get started. On your computer, open up a file manager. Create and name a folder. Don’t use spaces in the name of the folder. Use underscores rather than spaces.

Creating the folder for php Shortcode plugin to add PHP code to WordPress posts or pages

Now, copy the text below. Then, open Notepad or a text editor and paste it into your text file. Name File the same as the folder name. and save the text file as a .php file in the folder you have created.

Plugin Name: Cheapasdiy Shortcode Plugin
Plugin URI:  
Description: Includes plugin for shortcode for use of php code.
Version:     1.0.0
Author:      Cheapasdiy
Author URI:
License:     None
License URI: None
*Name of Shortcode Function*/
	function cheapasdiy_shortcode_function( $atts ) {
/*Add Your PHP Code here*/
return 'Hello this is a link to <a href="">CheapAsDiy</a>';
/*Sets the Name of ShortCode
 and Calls the Function*/
( 'diy_shortcode_name', 'cheapasdiy_shortcode_function' );
Creating and saving your php Shortcode wordpress plugin

The next step is to change your folder to a zip file. Upload the zip file as a plugin onto your WordPress site; now you’re all set.

Installing Short Code Plugin

Now go to the dashboard of your WordPress site to change or add more PHP code to the plugin. Easily edit this by clicking on plugins, plugin editor, and select the plugin to edit the PHP code. You can add as many shortcodes as you need to this plugin.

Adding PHP code to your WordPress Plugin

If you want to see this plugin in action, please click on the link below.

CheapAsDiy site content is completely free for you to use.  If our content helped you and saved you money.  Please feel free to Donate Here. Even 1 dollar makes a big difference.

User Rating: Be the first one !

About cheapasdiyguy

Leave a Reply

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

By continuing to use the site, you agree to the use of cookies. Privacy Policy

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.