Showing posts with label widget. Show all posts
Showing posts with label widget. Show all posts

Wednesday, 2 November 2011

How to add shortcodes in wordpress sidebar text widget?


In wordpress we have a nice concept called shortcodes. A shortcode is WordPress-specific codes that will do the things in an easy way. We have several default shortcodes and a shortcode will be inserted in a post or page file by embedding square braces.

Once I got a requirement to add the shortcode in the sidebar. So I just edited the sidebar.php file and added shortcode in the sidebar. As a developer I know how to add the code in the file so i can do it in that way. This notes is for the one who does not know how to embed the code.  For this add the following line of code to your theme functions.php file.

add_filter('widget_text', 'do_shortcode');

Enjoy using the shortcodes


Thursday, 28 July 2011

How to add shortcode to wordpress widget?


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.
  1. Login into wordpress admin page and go to the Theme Editor — i.e. select Apperance > Editor from admin menu.

  2. Select Functions or functions.php from the list of files in the right panel,and click on it to load it into the editor.

  3. Then add the following line of php code.
       add_filter('widget_text', 'do_shortcode');          
  1. 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.