Creating your own Shortcodes in a WordPress theme
read more

Creating your own Shortcodes in a WordPress theme


Shortcodes are a very useful tool once you know what you’re doing with them; they can provide additional options and open up new possibilities for saving time when you are editing your posts/widgets. You can use them to add a non-standard element to your post, or to generate a specified HTML structure instantly using one word instead of typing the full HTML manually every time.

For example; if we’re editing a new post for our blog and want to add a nice button, we can just use add the [button] shortcode in our text. Then, the HTML structure that we’ve specified in the button shortcode function will be added into our post content, and any pre-prepared CSS styles will take care of the button’s appearance. It’s a very simple and user-friendly solution.

Not that there’s anything stopping you typing the HTML structure manually every time, but doing so is inconvenient, time-consuming, and there’s always the risk that we’ll forget to close an HTML tag which will break our page layout and wastes more time to fix.