In WordPress you can’t add php code into posts by default. Sure, you can use Exec-PHP plugin that will let you do that but it is not the best option.

A community accepted way to add some advanced code, or show something depending on the status of the user viewing the post can be achieved trough shortcodes. They can be also used to post a predefinet piece of data or one stored in the database.

Here is how you can create a shortcode.

If you are developing a plugin, add the following code in your plugin file. If you want to just add a shorcode you can insert the code in functions.php file of your theme.

function shortc_func($atts) {
return "This is a text";
}
add_shortcode('shortc', 'shortc_func');

To add your shrotcode to your post just add the following in the text editor:

[shortc]

Lucian Apostol

Lucian Apostol is the owner of Flame Scorpion, he is a Web developer for 7 years and his mission is to share with you what he knows.

Website - More Posts