Using php in WordPress articles [shortcode].


Don’t you think it would be convenient if you could use php in your wordpress articles?
However, wordpress does not allow you to use php directly in the editor for security reasons.

If you really want to embed dynamic content in php, here is an alternative: create the content in an external file and load it into the article as a shortcode.

This is a very simple method where you just need to add a simple setting to the “fanctions.php” of your theme and place the files you want to load in the specified location.
Please check it out.

How to create your own shortcodes

First, you will need to create a shortcode in your WordPress theme in
Write the shortcode settings in fanctions.php in your WordPress theme.

This sample assumes that you create a folder called shortcode in the theme folder and place the php to be loaded there.

If you are using a child theme, replace line 6 with the following “Description for using a child theme”.

Normal description

Description for using a child theme

Next, create the php file that you want to load in the article.
The contents of the file will be omitted. Place the file you created in the “shortcode” section of your theme folder.

If the name of the file you placed is “example.php”, the description of the shortcode in the article will be as follows

Put the name of the file without the extension in ” file=’ ‘ “.
This will reflect the contents of example.php as part of the content in the article.