Edit: As of WordPress 3.3, shortcodes now work in widgets (the first line of code has been added to WP core). But you'll still need to create the other functions.
WordPress doesn't support shortcodes in sidebars by default, but it's easy to fix. I'm going to focus on a specific use of shortcodes in a sidebar, but you could use this technique for any shortcode.
When migrating a WordPress website from my development server to a client's, I do a find/replace in the database for the old URL's. But the URL's in the sidebar remain unchanged, due to the way they're stored in the database.
WordPress gives you some handy functions for displaying the site's url ( bloginfo('url') ), the wordpress directory ( bloginfo('wpurl') ), and the child theme directory ( bloginfo('stylesheet_directory') ). I now create three shortcodes and use them instead of hardcoding URL's in the sidebar. This is useful if you're displaying images in the sidebar and don't want to manually update them after migration.
No comments yet