<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digging into WordPress &#187; widgets</title>
	<atom:link href="http://digwp.com/tag/widgets/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:03:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Customize Your WordPress Dashboard</title>
		<link>http://digwp.com/2010/10/customize-wordpress-dashboard/</link>
		<comments>http://digwp.com/2010/10/customize-wordpress-dashboard/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 06:51:46 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[dashboard]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2950</guid>
		<description><![CDATA[There are many ways to customize the WordPress Dashboard. Over the years, the Dashboard has evolved into a highly flexible information portal, enabling an overall, big-picture view of the main components of your site, while also providing granular data on everything from recent comments and plugin updates to incoming links and WordPress news. And that&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>There are many ways to customize the WordPress Dashboard. Over the years, the Dashboard has evolved into a highly flexible information portal, enabling an overall, big-picture view of the main components of your site, while also providing granular data on everything from recent comments and plugin updates to incoming links and WordPress news. And that&rsquo;s just the <em>default</em> functionality, there are also a <em>ton</em> of <a href="http://wordpress.org/extend/plugins/tags/dashboard" title="All plugins tagged 'dashboard' in the Plugin Directory">dashboard widgets and plugins</a> available in the <a href="http://wordpress.org/extend/plugins/search.php?q=dashboard+widgets" title="Search the Plugin Directory for 'dashboard widgets'">WordPress Plugin Directory</a> that you can use to transform your Dashboard into just about anything, or even disable it completely.</p>
<p><span id="more-2950"></span></p>
<h3>The easiest way to customize your Dashboard</h3>
<p>For many WordPress sites, you can achieve complete Dashboard nirvana by simply selecting a few options in the Dashboard&rsquo;s <strong>Screen Options</strong> panel. On the Dashboard, click the tab in the upper-right corner to toggle open your Dashboard configuration options. There you can choose your Dashboard preferences:</p>
<ul>
<li>Choose the widgets you want to show on the Dashboard</li>
<li>Choose how many columns to use for the screen layout</li>
</ul>
<p>Here is a screenshot illustrating this awesome functionality:</p>
<p><img src="http://digwp.com/wp-content/blog-images/customize-dashboard-02.gif" alt="[ Dashboard Screen Options ]" /></p>
<p>The ability to hide or show any default widgets makes it <em>easy</em> to set things up on the fly. Maybe your client doesn&rsquo;t need the community news feed? Disable it. Maybe you&rsquo;re getting some fatal errors (e.g., &ldquo;Allowed memory size of 33554432 bytes exhausted&rdquo;) for the Incoming Links and Plugins widgets? You could spend time on the issue or you could just disable any widgets giving you grief. For my personal sites, I like to disable everything except for Right Now, Recent Comments, and Incoming Links, and display them in two columns. Keeps the Dashboard clean and fast. But to each their own! That&rsquo;s the beauty of WordPress&nbsp;:)</p>
<h3>Customizing and disabling the Dashboard using plugins</h3>
<p>Most of the time, the built-in Screen Options are all you need to customize your WordPress Dashboard. For more control over which users actually <em>see</em> the dashboard and its widgets, here are two great plugins (among <a href="http://wordpress.org/extend/plugins/search.php?q=hide+dashboard" title="Search the Plugin Directory for 'hide dashboard'">many</a>):</p>
<ul>
<li>KP Design&rsquo;s <a href="http://wordpress.org/extend/plugins/wp-hide-dashboard/" title="WP Hide Dashboard">WP Hide Dashboard</a></li>
<li>sant0sk1&rsquo;s <a href="http://wordpress.org/extend/plugins/clean-wp-dashboard/" title="Clean WP Dashboard">Clean WP Dashboard</a></li>
</ul>
<p>The <em>WP Hide Dashboard</em> plugin really cleans things up by removing the Dashboard and Tools menu, the Screen Options section, and even the Help button on the Profile page. It also prevents Dashboard access to users assigned to the Subscriber role. It&rsquo;s also a <em>breeze</em> to use: just install and it works &ndash; no configuration necessary.</p>
<p>The <em>Clean WP Dashboard</em> plugin doesn&rsquo;t remove any of the Dashboard menus, Screen Options, or Help button, but it does enable you to remove any of the following Dashboard widgets for <em>all</em> users:</p>
<ul>
<li>Right Now</li>
<li>Incoming Links</li>
<li>Plugins</li>
<li>Recent Comments</li>
<li>QuickPress</li>
<li>Recent Drafts</li>
<li>WP Dev Blog</li>
<li>Other WP News</li>
</ul>
<p>With this plugin, disabling any of these default widgets also removes their corresponding display option from the Screen Options menu, but leaves all the settings and menus in place for other widgets. This also is a very simple plugin to use: just enable, pick your widgets, and done. Here is another screenshot to help illustrate how this plugin is useful for customizing your dashboard:</p>
<p><img src="http://digwp.com/wp-content/blog-images/customize-dashboard-03.gif" alt="[ Clean WP Dashboard ]" /></p>
<p>Even with WordPress&rsquo; default Screen Options and helpful plugins such as these, there are times when you&rsquo;ll want to do even more with the customization of your Dashboard. Fortunately, with WordPress you&rsquo;re not limited to default functionality and widgets &ndash; by adding a few lines of code to your theme&rsquo;s <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/" title="WordPress functions.php Template with 15 Essential Custom Functions">functions.php file</a>, you can make just about anything happen.</p>
<h3>Customizing your Dashboard with the functions.php file</h3>
<p>There are <a href="http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/" title="WordPress Custom functions.php Template, Part 2">many cool ways</a> to customize your WordPress site using your theme&rsquo;s <code>functions.php</code> file. The benefits of using <code>functions.php</code> include:</p>
<ul>
<li>Direct control over site functionality</li>
<li>Follows your theme to other sites (portability)</li>
<li>You don&rsquo;t need to rely on a plugin</li>
<li>Set it and forget &ndash; no upgrades or fiddling</li>
</ul>
<p>I would argue that in some cases, it&rsquo;s actually <em>easier</em> to use <code>functions.php</code> than it is to hunt down, install, configure, and manage a plugin. Just grab a code snippet (or write your own) and paste it anywhere into your theme&rsquo;s <code>functions.php</code> file. Test well and you&rsquo;re done. Let&rsquo;s check out some <code>functions.php</code> snippets useful for customizing the WordPress Dashboard.</p>
<h4>Create your own Dashboard widget</h4>
<p>You can display just about <em>anything</em> in your Dashboard. If default tools and other plugins aren&rsquo;t getting you there, WordPress makes it easy to create your own. The easiest way to get started is to add the following to <code>functions.php</code>:</p>
<pre><code>// example custom dashboard widget
function custom_dashboard_widget() {
	echo "&lt;p&gt;Dearest Client, Here&amp;rsquo;s how to do that thing I told you about yesterday...&lt;/p&gt;";
}
function add_custom_dashboard_widget() {
	wp_add_dashboard_widget('custom_dashboard_widget', 'How to Do Something in WordPress', 'custom_dashboard_widget');
}
add_action('wp_dashboard_setup', 'add_custom_dashboard_widget');</code></pre>
<p>Here we are using two functions to do the job. The first one contains the content of the custom widget. The second one turns the output of the first function into a widget. And finally, we run the second function when the Dashboard is set up. Once this code is in place, visit your Dashboard. You should see your custom widget displayed like so:</p>
<p><img src="http://digwp.com/wp-content/blog-images/customize-dashboard-01.gif" alt="[ Custom Dashboard Widget ]" /></p>
<p>Once you see how things work, it&rsquo;s just a matter of adding the content and functionality. You could add a calendar, list recent subscribers, import feeds, display images, post tutorials, and just about anything else imaginable.</p>
<h4>Disable default widgets</h4>
<p>You can also use <code>functions.php</code> to <strong>disable default Dashboard widgets without a plugin</strong>. Using the code found in the <a href="http://codex.wordpress.org/Dashboard_Widgets_API#Advanced:_Removing_Dashboard_Widgets" title="Advanced: Removing Dashboard Widgets">WordPress Codex</a>, you would add this to your <code>functions.php</code> file:</p>
<pre><code>// disable default dashboard widgets
function remove_dashboard_widgets() {

	global $wp_meta_boxes;

	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);

	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
add_action('wp_dashboard_setup', 'remove_dashboard_widgets');</code></pre>
<p>This works fine, but it seems better to use the WordPress <abbr title="Application Programming Interface">API</abbr>:</p>
<pre><code>// disable default dashboard widgets
function disable_default_dashboard_widgets() {

	remove_meta_box('dashboard_right_now', 'dashboard', 'core');
	remove_meta_box('dashboard_recent_comments', 'dashboard', 'core');
	remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
	remove_meta_box('dashboard_plugins', 'dashboard', 'core');

	remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
	remove_meta_box('dashboard_recent_drafts', 'dashboard', 'core');
	remove_meta_box('dashboard_primary', 'dashboard', 'core');
	remove_meta_box('dashboard_secondary', 'dashboard', 'core');
}
add_action('admin_menu', 'disable_default_dashboard_widgets');</code></pre>
<p>I&rsquo;m using this code to clean up the Dashboard of my <a href="http://eChunks.com/" title="Random Eye Snacks">eChunks</a> site, and it works like a dream. You can also set the code to <strong>display the default widgets only for Admins</strong> by replacing the last line with this conditional snippet:</p>
<p><code>if (!current_user_can('manage_options')) {</code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>add_action('wp_dashboard_setup', 'disable_default_dashboard_widgets');</code><br />
<code>}</code></p>
<p>This code basically says, &ldquo;disable the default Dashboard widgets <em>only if</em> the user can&rsquo;t manage options. So Admins will see the widgets but everyone else will not.</p>
<h4>Disable plugin and other non-default widgets</h4>
<p>If you recall from the second screenshot in this article, only the <a href="http://simple-press.com/">Simple:Press</a> widget was displayed in the Dashboard. Even with the default widgets disabled, widgets from plugins and the <code>functions.php</code> file are displayed. As with the default widgets, you can simply hide these widgets using the Screen Options panel, or you can completely disable them using a few lines code in your <code>functions.php</code> file.</p>
<p>To disable a non-default Dashboard widget, you first need the name of the widget, which is available in the source code as one of the <code>&lt;div&gt;</code> <code>id</code>s. For example, the Simple:Press widget is wrapped in the following markup:</p>
<p><code>&lt;div id="sf_announce" class="postbox"&gt;</code></p>
<p>And so the name of the widget is &ldquo;<code>sf_announce</code>&rdquo;. Likewise, our custom Dashboard widget is wrapped with this:</p>
<p><code>&lt;div id="custom_dashboard_widget" class="postbox"&gt;</code></p>
<p>Once you have the name of the widget you would like to remove, just add another line to the <code>disable_default_dashboard_widgets()</code> function provided above:</p>
<pre><code>// disable default dashboard widgets
function disable_default_dashboard_widgets() {

	// disable default dashboard widgets
	remove_meta_box('dashboard_right_now', 'dashboard', 'core');
	remove_meta_box('dashboard_recent_comments', 'dashboard', 'core');
	remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
	remove_meta_box('dashboard_plugins', 'dashboard', 'core');

	remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
	remove_meta_box('dashboard_recent_drafts', 'dashboard', 'core');
	remove_meta_box('dashboard_primary', 'dashboard', 'core');
	remove_meta_box('dashboard_secondary', 'dashboard', 'core');

	// disable Simple:Press dashboard widget
	remove_meta_box('sf_announce', 'dashboard', 'normal');
}
add_action('admin_menu', 'disable_default_dashboard_widgets');</code></pre>
<p>Other Dashboard widgets may be disabled in the same way. Just replace <code>sf_announce</code> with the name of your widget. If you have a lot of widgets to disable, you may not feel like digging through source code to decipher their names. Fortunately, there&rsquo;s an easier way to get that information.</p>
<h4>List all Dashboard widgets</h4>
<p>To get a list of all active Dashboard widgets, add the following snippet to your theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>// list active dashboard widgets
function list_active_dashboard_widgets() {
	global $wp_meta_boxes;
	foreach (array_keys($wp_meta_boxes['dashboard']['normal']['core']) as $name) {
		echo '&lt;div&gt;' . $name . '&lt;/div&gt;';
	}
}
add_action('wp_dashboard_setup', 'list_active_dashboard_widgets');</code></pre>
<p>Then go to your Admin and hit refresh. At the top of the page, you will see a list of all active widgets. Note that this method is a little rough because the list is basically spit out before all of the content, so make sure you&rsquo;re not executing on a production site. Or be quick about it. Or use the conditional <code>current_user_can</code> code from above. Either way, this is the easiest way to grab a list of all active Dashboard widgets.</p>
<h3>Wrap up</h3>
<p>What&rsquo;s the take-home message from all of this? WordPress makes it easy to customize your Dashboard in three ways: default Screen Options, plugins, and <code>functions.php</code> code. Using any combination of these three methods, you have complete control over the appearance and functionality of your WordPress Dashboard.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/10/customize-wordpress-dashboard/">Permalink</a> | <a href="http://digwp.com/2010/10/customize-wordpress-dashboard/#comments">14 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/10/customize-wordpress-dashboard/&title=Customize Your WordPress Dashboard">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/dashboard/" rel="tag">dashboard</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/10/customize-wordpress-dashboard/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Call a Widget with a Shortcode</title>
		<link>http://digwp.com/2010/04/call-widget-with-shortcode/</link>
		<comments>http://digwp.com/2010/04/call-widget-with-shortcode/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 17:30:03 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1752</guid>
		<description><![CDATA[We covered how to run a shortcode in a widget. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably [...]]]></description>
			<content:encoded><![CDATA[<p>We covered how to <a href="http://digwp.com/2010/03/shortcodes-in-widgets/">run a shortcode in a widget</a>. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably a custom page template for that widgetized area and such. I wanted to just put [widget widget_name="my_widget"] in the pages content and have that widget pop in. Turns out it wasn&#8217;t as easy I wanted it to be, but it&#8217;s not that bad&#8230;</p>
<p><span id="more-1752"></span></p>
<p>The answer was creating a custom function for the functions.php file which would output any widget by name. There is a function just for that: <code>the_widget()</code> (<a href="http://codex.wordpress.org/Template_Tags/the_widget">incomplete codex page</a>).</p>
<h3>The logic</h3>
<ol>
<li>Test if widget exists</li>
<li>If it does&#8230;
<ol>
<li>Start capturing output</li>
<li>Output widget</li>
<li>End capturing output</li>
<li>Return captured output</li>
</ol>
</li>
<li>If it doesn&#8217;t exist&#8230;
<ol>
<li>Output fail message</li>
</ol>
</li>
</ol>
<h3>The code for functions.php</h3>
<pre><code>function widget($atts) {
    
    global $wp_widget_factory;
    
    extract(shortcode_atts(array(
        'widget_name' =&gt; FALSE
    ), $atts));
    
    $widget_name = wp_specialchars($widget_name);
    
    if (!is_a($wp_widget_factory-&gt;widgets[$widget_name], 'WP_Widget')):
        $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
        
        if (!is_a($wp_widget_factory-&gt;widgets[$wp_class], 'WP_Widget')):
            return '&lt;p&gt;'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'&lt;strong&gt;'.$class.'&lt;/strong&gt;').'&lt;/p&gt;';
        else:
            $class = $wp_class;
        endif;
    endif;
    
    ob_start();
    the_widget($widget_name, $instance, array('widget_id'=&gt;'arbitrary-instance-'.$id,
        'before_widget' =&gt; '',
        'after_widget' =&gt; '',
        'before_title' =&gt; '',
        'after_title' =&gt; ''
    ));
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
    
}
add_shortcode('widget','widget'); </code></pre>
<h3>Usage</h3>
<p>Now in Post/Page content, you can use the widget just by referencing it by name:</p>
<pre><code>[widget widget_name="Your_Custom_Widget"]</code></pre>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/04/call-widget-with-shortcode/">Permalink</a> | <a href="http://digwp.com/2010/04/call-widget-with-shortcode/#comments">15 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/04/call-widget-with-shortcode/&title=Call a Widget with a Shortcode">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/04/call-widget-with-shortcode/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Declare Multiple Widgetized Areas</title>
		<link>http://digwp.com/2010/03/declare-multiple-widgetized-areas/</link>
		<comments>http://digwp.com/2010/03/declare-multiple-widgetized-areas/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 12:24:26 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1686</guid>
		<description><![CDATA[Have a bunch of different areas you wish to declare as a widgetized area? Save repetative code by creating a quick array of their names, then loop through that array calling the register_sidebar() function on each one. Elementary PHP stuff here, but hey, it just saved me quite a few lines of code in a [...]]]></description>
			<content:encoded><![CDATA[<p>Have a bunch of different areas you wish to declare as a widgetized area? Save repetative code by creating a quick array of their names, then loop through that array calling the register_sidebar() function on each one. Elementary PHP stuff here, but hey, it just saved me quite a few lines of code in a widget-heavy theme I am working on.</p>
<pre><code>if ( function_exists('register_sidebar') ) {

    $allWidgetizedAreas = array("Homepage Left", "Homepage Right", "Sidebar One", "Movies", "Admin");
    
    foreach ($allWidgetizedAreas as $WidgetAreaName) {
    
        register_sidebar(array(
           'name'=&gt; $WidgetAreaName,
           'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s left half"&gt;',
           'after_widget' =&gt; '&lt;/div&gt;',
           'before_title' =&gt; '&lt;h3 class="widgettitle"&gt;',
           'after_title' =&gt; '&lt;/h3&gt;',
        ));
    
    }

}</code></pre>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/declare-multiple-widgetized-areas/">Permalink</a> | <a href="http://digwp.com/2010/03/declare-multiple-widgetized-areas/#comments">7 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/declare-multiple-widgetized-areas/&title=Declare Multiple Widgetized Areas">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/declare-multiple-widgetized-areas/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Shortcodes in Widgets</title>
		<link>http://digwp.com/2010/03/shortcodes-in-widgets/</link>
		<comments>http://digwp.com/2010/03/shortcodes-in-widgets/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 13:07:32 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1560</guid>
		<description><![CDATA[I had occasion the other day to run a shortcode inside of a text widget. You know shortcodes&#8230; we talk about them all the time. They are keywords in [square brackets] that do something special. Sometimes something really simple like returning a string (so you can have a global location to change that string) or [...]]]></description>
			<content:encoded><![CDATA[<p>I had occasion the other day to run a shortcode inside of a text widget. You know shortcodes&#8230; we talk about them <a href="http://digwp.com/tag/shortcode/">all the time</a>. They are keywords in [square brackets] that do something special. Sometimes something really simple like returning a string (so you can have a global location to change that string) or something complicated like call a plugin that does something fancy like build a photo gallery.</p>
<p>But alas&#8230;</p>
<div class="image-wrap">
<img src="http://digwp.com/wp-content/blog-images/shortcodeinwidget.png" width="371" height="222" alt="" title="" /><br />
This ain&#8217;t gonna work &#8220;out-of-the-box&#8221;
</div>
<p><span id="more-1560"></span></p>
<p>After tinkering with some far-too-complicated solutions, someone on Twitter helped me with a deliciously simple solution: Just add this to your functions.php file:</p>
<pre><code>add_filter('widget_text', 'do_shortcode');</code></pre>
<p>This will ensure that the text content of widgets is parsed for shortcodes and those shortcodes are ran. Awesome.</p>
<p>Stephanie Leary wrote a great article on <a href="http://sillybean.net/wordpress/content/using-shortcodes-everywhere/">Using Shortcodes Everywhere</a>, which covers this as well as using shortcodes in a bunch of other places: Comments, templates, excerpts, etc.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/shortcodes-in-widgets/">Permalink</a> | <a href="http://digwp.com/2010/03/shortcodes-in-widgets/#comments">4 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/shortcodes-in-widgets/&title=Shortcodes in Widgets">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/shortcode/" rel="tag">shortcode</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/shortcodes-in-widgets/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Widgetize Your WordPress Theme in 2 Steps</title>
		<link>http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/</link>
		<comments>http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 17:47:30 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1379</guid>
		<description><![CDATA[Working on a new theme for the next Digging into WordPress book update, I found myself really getting into the whole &#8220;widgetizing&#8221; thing. Widgets enable non-technical users to customize your theme according to their specific layout needs, and with so many different widgets available, the possibilities are endless. You may have thought about widgets as [...]]]></description>
			<content:encoded><![CDATA[<p>Working on a new theme for the next Digging into WordPress book update, I found myself really getting into the whole &ldquo;widgetizing&rdquo; thing. Widgets enable non-technical users to customize your theme according to their specific layout needs, and with <a href="http://codex.wordpress.org/WordPress_Widgets" title="WordPress Widgets">so many</a> different widgets available, the possibilities are endless. You may have thought about widgets as something you do in the sidebar, but there is no reason to stop there. You can widgetize just about every part of your theme. In this post, we&rsquo;ll show you how to do widgetize your theme in <strong>two easy steps</strong>. Once we get the basics down, we&rsquo;ll dig into some <em>sweet tips and tricks</em>.</p>
<p><span id="more-1379"></span></p>
<h3>Widgetize Your WordPress Theme: Step 1</h3>
<p>Make a fist and howl at the monitor. Then place this code into your active theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>if (function_exists('register_sidebar')) {

	register_sidebar(array(
		'name' =&gt; 'Widgetized Area',
		'id'   =&gt; 'widgetized-area',
		'description'   =&gt; 'This is a widgetized area.',
		'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
		'after_widget'  =&gt; '&lt;/div&gt;',
		'before_title'  =&gt; '&lt;h4&gt;',
		'after_title'   =&gt; '&lt;/h4&gt;'
	));

}</code></pre>
<p>This is all that is needed for the first step. Once this widgetizing code is placed in your <code>functions.php</code> file, proceed to Step 2. The remainder of this section is explanation.</p>
<p>This code checks to make sure that the current version of WordPress supports widgets, and then declares an array of values that will be used to create the widgetized area in your theme. Here are the different values:</p>
<ul>
<li><code>name</code> &ndash; the name of the widgetized area as displayed in the <acronym title="WordPress">WP</acronym> Admin</li>
<li><code>id</code> &ndash; a unique identifier for your widgetized area</li>
<li><code>description</code> &ndash; description of the widgetized area</li>
<li><code>before_widget</code> &ndash; the markup generated before any user-added widgets</li>
<li><code>after_widget</code> &ndash; the markup generated after any user-added widgets</li>
<li><code>before_title</code> &ndash; the markup generated before the title of any user-added widgets</li>
<li><code>after_title</code> &ndash; the markup generated after the title of any user-added widgets</li>
</ul>
<p>So, given these parameters, our widgetizing code would result in the following output, say, if the built-in Search widget were added to our widgetized area:</p>
<pre><code>&lt;div id="search-3" class="widget widget_search"&gt;
	&lt;h4&gt;Search&lt;/h4&gt;
	&lt;form role="search" method="get" id="searchform" action="http://localhost/283/" &gt;
		&lt;div&gt;
			&lt;label class="screen-reader-text" for="s"&gt;Search for:&lt;/label&gt;
			&lt;input type="text" value="" name="s" id="s" /&gt;
			&lt;input type="submit" id="searchsubmit" value="Search" /&gt;
		&lt;/div&gt;
	&lt;/form&gt;
&lt;/div&gt;</code></pre>
<p>Note the markup created for the opening <code>&lt;div&gt;</code>, which gets its attribute information based on the wild-card matching specified in our widgetizing array. To see this more clearly, examine the following side-by-side comparison of the <code>sprintf</code> directives and the resulting <acronym title="(eXtensible) Hypertext Markup Language">(X)HTML</acronym> source code:</p>
<pre><code>'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
&lt;div id="search-3" class="widget widget_search"&gt;</code></pre>
<p>Hopefully the relationship is clear. This is a powerful way to ensure that all widgets have a similar class names and unique <acronym title="Identification">ID</acronym>s, which are important for easy <acronym title="Cascading Style Sheets">CSS</acronym> styles.</p>
<p>Let&rsquo;s continue with Step 2..</p>
<h3>Widgetize Your WordPress Theme: Step 2</h3>
<p>Finally, add the following code to the location in your theme&rsquo;s template file(s) where you would like the widgetized area to appear:</p>
<pre><code>&lt;div id="widgetized-area"&gt;

	&lt;?php if (function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('widgetized-area')) : else : ?&gt;

	&lt;div class="pre-widget"&gt;
		&lt;p&gt;&lt;strong&gt;Widgetized Area&lt;/strong&gt;&lt;/p&gt;
		&lt;p&gt;This panel is active and ready for you to add some widgets via the WP Admin&lt;/p&gt;
	&lt;/div&gt;

	&lt;?php endif; ?&gt;

&lt;/div&gt;</code></pre>
<p>With both steps complete, your theme should now feature a widgetized area in the location of your choosing. Nothing else needs to be done at this point. If you get it, then get to it and continue developing your theme. For more information and some juicy tips and tricks, continue reading.</p>
<p>Let&rsquo;s examine the code used in this second step. Everything located between the <code>if</code>/<code>endif</code> statements will be output to the browser when no widgets have been activated. This is a good place to inform the user that the area is widgetized and may be customized via the Widgets area in the WordPress Admin. I also include a &ldquo;<code>pre-widget</code>&rdquo; class to help style the pre-widget area. With multiple widgetized areas on a page, having a class name to hang styles on is super nice.</p>
<p>Also, note that we are using the <code>id</code> specified in the widgetizing array (refer to Step 1) as the parameter value for the specific <code>dynamic_sidebar()</code> check in the third line.</p>
<h3>Multiple widgetized areas</h3>
<p>So we now have a nice, widgetized sidebar. But why stop there? Implementing additional widgetized areas is as simple as replicating the code in Step 1 and Step 2. For example, let&rsquo;s say we wanted to widgetize the header, sidebar, and footer areas of our theme. We would be put this in our <code>functions.php</code> file:</p>
<pre><code>if (function_exists('register_sidebar')) {

	register_sidebar(array(
		'name' =&gt; 'Header',
		'id'   =&gt; 'header',
		'description'   =&gt; 'This is the widgetized header.',
		'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
		'after_widget'  =&gt; '&lt;/div&gt;',
		'before_title'  =&gt; '&lt;h4&gt;',
		'after_title'   =&gt; '&lt;/h4&gt;'
	));
	register_sidebar(array(
		'name' =&gt; 'Sidebar',
		'id'   =&gt; 'sidebar',
		'description'   =&gt; 'This is the widgetized sidebar.',
		'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
		'after_widget'  =&gt; '&lt;/div&gt;',
		'before_title'  =&gt; '&lt;h4&gt;',
		'after_title'   =&gt; '&lt;/h4&gt;'
	));
	register_sidebar(array(
		'name' =&gt; 'Footer',
		'id'   =&gt; 'footer',
		'description'   =&gt; 'This is the widgetized footer.',
		'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
		'after_widget'  =&gt; '&lt;/div&gt;',
		'before_title'  =&gt; '&lt;h4&gt;',
		'after_title'   =&gt; '&lt;/h4&gt;'
	));

}</code></pre>
<p>..and then we would place the following code chunks into their respective locations within our theme template files:</p>
<pre><code>&lt;div id="widgetized-header"&gt;

	&lt;?php if (function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('header')) : else : ?&gt;

	&lt;div class="pre-widget"&gt;
		&lt;p&gt;&lt;strong&gt;Widgetized Header&lt;/strong&gt;&lt;/p&gt;
		&lt;p&gt;This panel is active and ready for you to add some widgets via the WP Admin&lt;/p&gt;
	&lt;/div&gt;

	&lt;?php endif; ?&gt;

&lt;/div&gt;
&lt;div id="widgetized-sidebar"&gt;

	&lt;?php if (function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('sidebar')) : else : ?&gt;

	&lt;div class="pre-widget"&gt;
		&lt;p&gt;&lt;strong&gt;Widgetized Sidebar&lt;/strong&gt;&lt;/p&gt;
		&lt;p&gt;This panel is active and ready for you to add some widgets via the WP Admin&lt;/p&gt;
	&lt;/div&gt;

	&lt;?php endif; ?&gt;

&lt;/div&gt;
&lt;div id="widgetized-footer"&gt;

	&lt;?php if (function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('footer')) : else : ?&gt;

	&lt;div class="pre-widget"&gt;
		&lt;p&gt;&lt;strong&gt;Widgetized Footer&lt;/strong&gt;&lt;/p&gt;
		&lt;p&gt;This panel is active and ready for you to add some widgets via the WP Admin&lt;/p&gt;
	&lt;/div&gt;

	&lt;?php endif; ?&gt;

&lt;/div&gt;</code></pre>
<p>That&rsquo;s all there is to it. Of course, you&rsquo;ll probably want to tweak the details to suit your specific needs, but these two steps are all you need to widgetize your WordPress theme. Now let&rsquo;s wrap things up with some juicy widgetizing tricks..</p>
<h3>Some Juicy Widgetizing Tricks</h3>
<p>Here are some sweet little tips for widgetizing your theme:</p>
<h4>Streamline &amp; organize custom widgets</h4>
<p>The first thing that I do after widgetizing a new theme is to include a separate &ldquo;<code>widgets.php</code>&rdquo; that contains all of the custom widgets. A simple line of code is all that is required to acheive this functionality:</p>
<p><code>if ($wp_version &gt;= 2.8) require_once(TEMPLATEPATH.'/widgets.php');</code></p>
<p>Place that code into your <code>functions.php</code> file and place all of your widgets into a file called <code>widgets.php</code>. Once in place, this method will ensure that your widgets are loaded and available for all supportive versions of WordPress. This is a great way to keep your theme files nice and organized.</p>
<h4>Replace WordPress&rsquo; default widgets</h4>
<p>Many of the default WordPress widgets leave something to be desired. Fortunately, it&rsquo;s super-easy to override any of the default widgets with your own creations. For example, here is one way to replace the default Search Widget with your own version:</p>
<pre><code>&lt;?php function custom_search_widget() { ?&gt;

&lt;form action="http://localhost/283/index.php" method="get"&gt;
	&lt;div&gt;
		&lt;label for="s"&gt;Site Search&lt;/label&gt;
		&lt;input id="s" name="s" alt="Search" type="text" /&gt;
	&lt;/div&gt;
&lt;/form&gt;

&lt;?php } if (function_exists('register_sidebar_widget'))

register_sidebar_widget(__('Search'), 'custom_search_widget'); ?&gt;</code></pre>
<h4>Hide unused widget areas</h4>
<p>An empty widgetized area of your theme can look strange, especially when <acronym title="Cascading Style Sheets">CSS</acronym> styles are applied to the container element. To prevent this from happening, we can wrap each of our widgetized areas with the following code:</p>
<pre><code>&lt;?php if (function_exists('is_sidebar_active') &amp;&amp; is_sidebar_active('sidebar')) { ?&gt;

&lt;!-- code from Step 2 or whatever you want --&gt;

&lt;?php } ?&gt;</code></pre>
<p>With this conditional code, widgetized areas will only be displayed if they contain at least one active widget. Nice&nbsp;:) Also note that this conditional technique works for displaying things other than widgets.</p>
<h3>More..?</h3>
<p>Hopefully this easy two-step widgetizing guide will be useful for you during your next round of theme development. As always, if you know of any other sweet widgetizing tricks, please share them in the comments!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/">Permalink</a> | <a href="http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/#comments">24 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/&title=How to Widgetize Your WordPress Theme in 2 Steps">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/02/how-to-widgetize-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Look Ma, Editable Text Regions</title>
		<link>http://digwp.com/2009/09/look-ma-editable-text-regions/</link>
		<comments>http://digwp.com/2009/09/look-ma-editable-text-regions/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 15:06:53 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=622</guid>
		<description><![CDATA[WordPress is a CMS. The whole idea being to manage content and make websites editable without having to wrangle code. Any theme can handle Posts and Pages, but what about those &#8220;smaller&#8221; areas. Little chunks of text placed around a design like a small &#8220;about&#8221; section, or the copy in the footer of a website. [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress is a CMS. The whole idea being to manage content and make websites editable without having to wrangle code. Any theme can handle Posts and Pages, but what about those &#8220;smaller&#8221; areas. Little chunks of text placed around a design like a small &#8220;about&#8221; section, or the copy in the footer of a website. A lot of times this text is hard-baked right into the theme, which isn&#8217;t a very friendly way to do things, as it can&#8217;t be updated by average Joe user.</p>
<p><img src="http://digwp.com/wp-content/blog-images/editable-region.png" width="590" height="439" alt="" title="" /></p>
<p><span id="more-622"></span></p>
<h3>Widgetize!</h3>
<p>If you are looking to add text to your sidebar, and your sidebar is already widgetized, this becomes trivially easy. In your Admin, go to <strong>Appearance > Widgets</strong> and drag the &#8220;text&#8221; widget into the your sidebar area on the right. You can then open up that widget and give it a title and text and save it.</p>
<p><img src="http://digwp.com/wp-content/blog-images/widgetize.jpg" width="590" height="581" alt="" title="" /></p>
<h3>Adding Multiple Regions</h3>
<p>There is a good chance that if your theme is widgetized, the only widgetable area is the sidebar. But you are by no means limited to having only one widgetized area. In order to add another, open your <code>functions.php</code> file and add another chunk of code like this:</p>
<pre><code>if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Footer Widgets',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}</code></pre>
<p>The &#8216;name&#8217; part is important, because we&#8217;ll be referencing that in a sec when we drop in the widgetization code. Most of the rest of this should be pretty self-explanatory. You provide the HTML code for what wraps the text you provide for a title and body of the widget. Those weird characters as part of the ID and class actually provide some nice useful hooks for each widget. The ID is literally a unique ID for the widget, and the classes designate the type of widget being used. The end result markup for a simple text widget will be something like this:</p>
<pre><code>&lt;div class="widget widget_text" id="text-4"&gt;
   &lt;div class="textwidget"&gt;
       &lt;p&gt;Â©2009 Digging into WordPress&lt;/p&gt;
   &lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>As you may have gathered, we are making an editable region in our footer to house the copyright information. In our <code>footer.php</code> file, we&#8217;ll drop in this code in an appropriate place to widgetize the area:</p>
<pre><code>&lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer Widgets') ) : ?&gt;
&lt;?php endif; ?&gt;</code></pre>
<p>All goes well, we now have a new widget area showing up in our Admin, in which to drag in widgets. Drag in a text widget, and you should be all set. It should be noted that while text widgets have a title and text area, you don&#8217;t <strong>have</strong> to use both, you can use one or the other if you want.</p>
<p><img src="http://digwp.com/wp-content/blog-images/footerwidget.png" width="311" height="176" alt="" title="" /></p>
<p>Fairly basic stuff, but this is great stuff for allowing users to be in more complete command of their sites!</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/09/look-ma-editable-text-regions/">Permalink</a> | <a href="http://digwp.com/2009/09/look-ma-editable-text-regions/#comments">21 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/09/look-ma-editable-text-regions/&title=Look Ma, Editable Text Regions">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/html/" rel="tag">HTML</a>, <a href="http://digwp.com/tag/maintenance/" rel="tag">maintenance</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/09/look-ma-editable-text-regions/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

