Shortcodes were introduced a long time ago, already in WordPress 2.5 and are a very useful tool that gives the blog editor additional possibilities to compose posts, add custom elements to them, without the need to manually place HTML fragments in them.
What are Shortcodes?
WordPress Shortcodes are special codes that allow users to add various elements to custom entries and pages without the need to manually include HTML elements in them. The first shortcodes in WordPress appeared already in 2008, during the presentation of version 2. 5. It was then that shortcodes started to be used by people working on this system.
How can Shortcode make work easier?
Imagine a situation where every time you finish an article on your company blog, you want to encourage the Internet user to visit a subpage with your company’s offer. You have designed an aesthetic and suggestive call to action, written a few thoughtful sentences and formatted the text so that it meets your expectations. Thanks to shortcode, instead of pasting a part of HTML code every time, you just need to add an appropriate command in square brackets, which you defined earlier in the template files.
This makes work easier and faster. Shortcodes are often used for repeated, longer texts, captions and graphics – such as logos. An additional advantage of this solution is that the shortcodes written by the developer can be changed in one place and the Modification will be introduced in all such codes on the site. A large part of shortcodes is generated by the plug-in installed in the theme. To fully use the possibilities of such an extension, you need to use them in the content of the entry.
The creation process itself is quite simple and does not require advanced PHP knowledge. The basic steps are:
- Creating a function that will be called by WordPress when it finds shortcode.
- Scorrection of shortcode by setting a Unique name.
- Function registration.
The whole code must be placed in the functions. php file or in a separate PHP file that will be referenced from the functions. php file.