Shortcode API in WordPress is fun. It helps you create small tags to address a chunk of code. All you do is write some [tag] and it returns the HTML/CSS/PHP code which you have saved inside it. Shortcodes can be used both in the Visual & the Text tab of your post/page editor. Let’s build a basic shortcode. Building shortcodes is fun. A beginner can easily code a shortcode in under one minute. Shortcodes are based upon a philosophy called DRY i.e. Don’t Repeat Yourself. E.g. I link [aboutme] page in my blog posts a lot. Same is the case with [contact] page link. Instead of writing these links each and every time, I have created shortcodes to help me optimize my workflow.
Coding a Shortcode in WordPress#
The algorithm of using shortcode API in WordPress is quite a simple one. All you have to do is write a function, return something and register a tag, which is then later used to render the shortcode. Let’s take an easy example;
All your posts are great source of information regarding WordPress, Keep posting and at my end i will implement to learn and improve. Thanks
You taught me something I was looking for from 6 months. It will help me creating WordPress plugins.
Thanks Ahmed.
Mentions