Wordpress has one great feature called shortcode for adding some special content to the posts or pages. Shortcodes are the keywords with the square brackets.
Ex: [gallery] is the shortcode to insert a gallery into a post or page.Place this shortcode in the page where you want to display the gallery.
Like this adding a shortcode to the page or post is very simple then we will get a question “how to add shortcode to widgets?”
If we add a shortcode to widget in the same process of adding to a post, then the shortcode ([gallery] in the above example) only be displayed instead of special content.
To add shortcode to the widget follow these steps.
- Login into wordpress admin page and go to the Theme Editor — i.e. select Apperance > Editor from admin menu.
- Select Functions or functions.php from the list of files in the right panel,and click on it to load it into the editor.
- Then add the following line of php code.
- Click on the Update File button to save the file.
That’s it.Now if you add shortcode to the sidebar it will process the code and will display the special content.