How to make a simple wordpress shortcode?

How to generate a simple wordpress shortcode, for example an ad

I think that is best to write a shortcode so we don’t have to insert same long info in every post.
For example insted of introducing this:

Into every post is simplier to insert this:

this will output the entire code above, and we can change the ad as we need without changing every post.

this is the code:

Replace from

with your needs.
You can make this as a plugin or you can write it in loaded function.php file (loaded theme).

custom shortcode
custom shortcode

Notice that I used return and not echo. If you use “echo” in the shortcode, the information will show up wherever the shortcode is processed, which isn’t necessarily where you actually added the shortcode. If you use “return”, the information will return exactly where you added the shortcode within the page.

In this way the ad from our case doesn’t appear at beginning of post, it appears exactly where we insert the shortcode.

In post just insert:


shortcode in post
shortcode in post
Last modified: August 28, 2017