{"id":47590,"date":"2006-03-22T02:19:19","date_gmt":"2006-03-22T02:19:19","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/widgets\/"},"modified":"2017-01-13T08:16:44","modified_gmt":"2017-01-13T08:16:44","slug":"widgets","status":"closed","type":"plugin","link":"https:\/\/wordpress.org\/plugins\/widgets\/","author":14353,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"1.0","stable_tag":"1.2.1","tested":"2.1.3","requires":"2.1","requires_php":"","requires_plugins":"","header_name":"Google Search widget","header_author":"Automattic, Inc.","header_description":"","assets_banners_color":"","last_updated":"2017-01-13 08:16:44","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"","header_author_uri":"http:\/\/automattic.com","rating":0,"author_block_rating":0,"active_installs":80,"downloads":374532,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":0},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0","1.1","1.2","1.2.1"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[2759,1141,162],"plugin_category":[43],"plugin_contributors":[77559,78230],"plugin_business_model":[],"class_list":["post-47590","plugin","type-plugin","status-closed","hentry","plugin_tags-customization","plugin_tags-theme","plugin_tags-widget","plugin_category-customization","plugin_contributors-mdawaffe","plugin_contributors-skeltoac","plugin_committers-andy","plugin_committers-skeltoac"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/widgets.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>It's called Sidebar Widgets because it allows you to move things (widgets)\naround, in and out of your sidebar. A widget is something that you might want\non your sidebar, such as a category list or the most recent comments or a link\nto your admin pages. There is even a widget that lets you type whatever you\nwant in the sidebar, such as some HTML or Javascript code.<\/p>\n\n<p><em>This plugin is <strong>NOT<\/strong> required for WordPress 2.2<\/em><\/p>\n\n<h3>Developing New Widgets<\/h3>\n\n<p>We included the Google Search and del.icio.us plugins as samples to show you\nwhat a widget plugin might look like. The Google Search widget is commented\nwithin inches of its life. Additionally, there are a few guidelines to follow.<\/p>\n\n<ul>\n<li>Don't execute any code while the plugin is loaded. Use the <code>plugins_loaded<\/code> hook\nor you risk fatal errors due to undefined functions, or missing the boat\ncompletely because your plugin loaded before the one it depends on.<\/li>\n<li>Use <code>register_sidebar_widget($name, $callback)<\/code> to add your widget to the admin\ninterface.<\/li>\n<li><p>Follow this template:<\/p>\n\n<pre><code>    function widget_myuniquewidget($args) {\n        extract($args);\n    ?&gt;\n            &lt;?php echo $before_widget; ?&gt;\n                &lt;?php echo $before_title . 'My Unique Widget' . $after_title; ?&gt;\n                Hello, World!\n            &lt;?php echo $after_widget; ?&gt;\n    &lt;?php\n    }\n    register_sidebar_widget('My Unique Widget', 'widget_myuniquewidget');\n<\/code><\/pre><\/li>\n<li><p>Don't leave out <code>$before_widget<\/code>, <code>$after_widget<\/code>, <code>$before_title<\/code>, or <code>$after_title<\/code>\nby accident. They are required for compatibility with various themes.<\/p><\/li>\n<li>Name your widget and its functions carefully. Those strings will be used as\nHTML attributes and you don't want to cause identical id's in a single HTML\ndocument.<\/li>\n<li>Localization is done internally to preserve the HTML id attribute. If you want\nyour widget name localized with a textdomain, pass <code>array($name, $textdomain)<\/code>\ninstead of <code>$name<\/code>.<\/li>\n<li>To accommodate multi-widgets (e.g. Text and RSS) you can also pass a\nreplacement value with the name: <code>array($name_as_sprintf_pattern, $textdomain,\n$replacement)<\/code>. See the source.<\/li>\n<li>You may use the variables mentioned above in different ways, or neglect them\nin some circumstances. Some widgets may not need a title, for example. Some\nwidgets will use the <code>$before_widget<\/code> and <code>$after_widget<\/code> several times, or as\narguments to tell another template tag how to format its output.<\/li>\n<li>Optionally, use this syntax to add a configuration page to the admin:\n  register_widget_control($name, $callback [, $width [, $height ] ]);\nYour callback will be used within the main form, so you don't have to worry\nabout <code>&lt;form&gt;<\/code> tags or a button to submit the form.<\/li>\n<li>Namespace your form elements so they don't conflict with other widgets.<\/li>\n<li>Each widget must have a unique name. You can replace an already-registered\nwidget by registering another one with the same name, supplying your own\ncallback.<\/li>\n<li>Any extra arguments to <code>register_sidebar_widget()<\/code> or <code>register_widget_control()<\/code>\nwill be passed to your callback. See the Text and RSS widgets for examples.<\/li>\n<li>Any widget or control can be \"unregistered\" by passing an empty string to the\nregistration function.<\/li>\n<li>There are some undocumented functions. You are encouraged to read the source\ncode and see how we've created the standard widgets using these functions.<\/li>\n<li>Please test your widgets with several themes other than Classic and Default\n(they both use the ul\/li\/h2 markup).<\/li>\n<li>Please audit the security of your widgets before distributing them.<\/li>\n<li>If you would like your widget to be considered for use on WordPress.com, send\na link (no attachments please) to widgets@wordpress.com and we'll have a look.<\/li>\n<\/ul>\n\n<!--section=installation-->\n<p>If you are using WordPress version 2.2 or later, you do not need to install this\nplugin;  WordPress itself already includes these features.<\/p>\n\n<p>First you have to put the files where they belong. We recommend putting all of\nthe php script files in wp-content\/plugins\/widgets and keeping any new widget\nplugins there unless another location is specified.<\/p>\n\n<p>Here it is in graphic form:<\/p>\n\n<pre><code>- wp-content\n    - plugins\n        - widgets\n            | delicious.php\n            | gsearch.php\n            | rss.png\n            | widgets.php\n    - themes\n        - classic\n            | functions.php (optional)\n            \\ sidebar.php (optional)\n        - default\n            | functions.php (optional)\n            \\ sidebar.php (optional)\n<\/code><\/pre>\n\n<p>It will also work if you store the RSS icon in wp-includes\/images. It's pretty\nflexible.<\/p>\n\n<p>Installing the plugin files isn't enough, however. You must have a theme that\nsupports sidebar widgets. To help you with that, we've included updated files\nfor the WordPress 2.0 Default Theme (Kubrick) and the Classic theme. There are\nmany themes that rely on Classic's script files, so it's probably a good idea to\ninstall the new Classic files unless you have modified the theme yourself.<\/p>\n\n<p>Don't forget to activate the Widgets plugin.<\/p>\n\n<!--section=faq-->\n<dl>\n<dt>I have installed and activated the plugin.  Now how do I use it?<\/dt>\n<dd><p>Assuming you chose the Kubrick theme, you should now see a \"Sidebar Widgets\"\nitem in the Presentation menu. This gives you a screen with two columns: a\npalette and a sidebar. The palette has all of the available widgets and the\nother column represents your sidebar. You can drag the widgets between the\ncolumns to create the exact combination that pleases you and your visitors.<\/p>\n\n<p>If you find that the widgets are not draggable, there are two likely causes:\nyou installed the scriptaculous files in the wrong place, or your web browser\nis not running the scripts.<\/p>\n\n<p>Some of the widgets will have a little icon on the right side of the draggable\nwidget device. Click that icon to reveal that widget's options. Click the X or\nthe area outside the options box to return to the widget page. Your options are\nnot saved until you click \"Save changes\" on the widget page.<\/p>\n\n<p>Two of the included widgets, Text and RSS, can be replicated several times.\nBelow the palette you will find forms to change the number of Text and RSS\nwidgets available. Reducing the number will only cause the extra widgets to be\nremoved from the visual interface; the contents of the widgets is preserved.<\/p><\/dd>\n<dt>What if I don't like Kubrick?<\/dt>\n<dd><p>You should. He was a visionary film producer. You are entitled to your opinion,\nhowever, so we'll give you a little tutorial on fixing up other themes.<\/p><\/dd>\n<dt>How do I fix up my theme?<\/dt>\n<dd><p>First you have to ask yourself, \"Do I know anything about my theme? Does it use\nan unordered list to create the sidebar?\" (If you can't answer that, you'll\nneed in-depth help on this task and that means either paying somebody a lot of\nmoney. Better yet, you can learn HTML. Sorry, we don't teach that here.)<\/p>\n\n<p>Here is an example of good sidebar markup:<\/p>\n\n<pre><code>&lt;ul id=\"sidebar\"&gt;\n &lt;li id=\"about\"&gt;\n  &lt;h2&gt;About&lt;\/h2&gt;\n  &lt;p&gt;This is my blog.&lt;\/p&gt;\n &lt;\/li&gt;\n &lt;li id=\"links\"&gt;\n  &lt;h2&gt;Links&lt;\/h2&gt;\n  &lt;ul&gt;\n   &lt;li&gt;&lt;a href=\"http:\/\/example.com\"&gt;Example&lt;\/a&gt;&lt;\/li&gt;\n  &lt;\/ul&gt;\n &lt;\/li&gt;\n&lt;\/ul&gt;\n<\/code><\/pre>\n\n<p>Notice that the entire sidebar is an unordered list and the titles are in <code>&lt;h2&gt;<\/code>\ntags. Not every theme is built this way and it's not necessary to do so, but\nit's the simplest, most common, most semantically correct and the most widget-\nfriendly sidebar markup there is. The element with id=\"links\" is the equivalent\nof one basic widget.<\/p>\n\n<p>When activated, the Dynamic Sidebar plugin gives you a few functions to use in\nyour template just like template tags. These functions let WordPress replace\nyour theme's sidebar with a dynamic one while still falling back on the old\nsidebar in case you deactivate the plugin or remove all the widgets.<\/p>\n\n<p>Here is an example of a basic sidebar upgrade using the same markup as above:<\/p>\n\n<pre><code>&lt;ul id=\"sidebar\"&gt;\n&lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar() ) : else : ?&gt;\n &lt;li id=\"about\"&gt;\n  &lt;h2&gt;About&lt;\/h2&gt;\n  &lt;p&gt;This is my blog.&lt;\/p&gt;\n &lt;\/li&gt;\n &lt;li id=\"links\"&gt;\n  &lt;h2&gt;Links&lt;\/h2&gt;\n  &lt;ul&gt;\n   &lt;li&gt;&lt;a href=\"http:\/\/example.com\"&gt;Example&lt;\/a&gt;&lt;\/li&gt;\n  &lt;\/ul&gt;\n &lt;\/li&gt;\n&lt;?php endif; ?&gt;\n&lt;\/ul&gt;\n<\/code><\/pre>\n\n<p>See? We just added two lines to the template and now it'll display a dynamic\nsidebar if possible, otherwise display the old sidebar. Disabling the plugin\nor removing all the widgets from the sidebar in the admin interface will cause\nthe old sidebar to be displayed.<\/p>\n\n<p>Now there is one more thing to be done to the theme. Assuming you are using\nWordPress 2.0 or higher, this change will be made within functions.php in your\ntheme's directory. (WordPress 1.5 users: we don't encourage people to use\nWordPress 1.5 anymore, so you won't find any help here. We don't even know if\nit's possible because it hasn't been tested.)<\/p>\n\n<p>Here is an example of functions.php for a theme that does not yet have such a\nfile (no blank lines at the beginning or end of the file, please):<\/p>\n\n<pre><code>&lt;?php\nif ( function_exists('register_sidebar') )\n    register_sidebar();\n?&gt;\n<\/code><\/pre>\n\n<p>That's it, just four lines. This code tells the plugin that your theme will need\nexactly one dynamic sidebar. At this point, your admin interface should have an\nextra item in the Presentation menu: Sidebar Widgets. Try dragging some widgets\nfrom the palette on the left into the box marked Sidebar 1 and saving your\nchanges. Got it working? Fantastic.<\/p><\/dd>\n<dt>My Sidebar isn't a list.  What do I do?<\/dt>\n<dd><p>We knew you'd ask that. You'll have to discover your sidebar's design pattern,\nthen use some extra parameters to tell the plugin how to format them to work\nwith your theme. We'll work through one example.<\/p>\n\n<p>Here's the original markup:<\/p>\n\n<pre><code>&lt;div id=\"sidebar\"&gt;\n &lt;div class=\"title\"&gt;About&lt;\/div&gt;\n &lt;p&gt;This is my blog.&lt;\/p&gt;\n &lt;div class=\"title\"&gt;Links&lt;\/div&gt;\n &lt;ul&gt;\n  &lt;li&gt;&lt;a href=\"http:\/\/example.com\"&gt;Example&lt;\/a&gt;&lt;\/li&gt;\n &lt;\/ul&gt;\n&lt;\/div&gt;\n<\/code><\/pre>\n\n<p>Yes, we've seen markup like this. It's the second most common sidebar design\npattern, which is why we chose it for the example. The first difference is that\nthe sidebar is not built inside a <code>&lt;ul&gt;<\/code> tag. That means we should not be wrapping\nany of our widgets in <code>&lt;li&gt;<\/code> tags. The second difference is that our titles are\nwrapped in <code>&lt;div class=\"title\"&gt;<\/code> instead of <code>&lt;h2&gt;<\/code> tags.<\/p>\n\n<p>We fix both of these issues by adding some parameters to the code in\nfunctions.php:<\/p>\n\n<pre><code>&lt;?php\nif ( function_exists('register_sidebar') )\n    register_sidebar(array(\n        'before_widget' =&gt; '', \/\/ Removes &lt;li&gt;\n        'after_widget' =&gt; '', \/\/ Removes &lt;\/li&gt;\n        'before_title' =&gt; '&lt;div class=\"title\"&gt;', \/\/ Replaces &lt;h2&gt;\n        'after_title' =&gt; '&lt;\/div&gt;', \/\/ Replaces &lt;\/h2&gt;\n    ));\n?&gt;\n<\/code><\/pre>\n\n<p>And here is the sidebar.php markup with our special template tags inserted:<\/p>\n\n<pre><code>&lt;div id=\"sidebar\"&gt;\n&lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar() ) : else : ?&gt;\n &lt;div class=\"title\"&gt;About&lt;\/div&gt;\n &lt;p&gt;This is my blog.&lt;\/p&gt;\n &lt;div class=\"title\"&gt;Links&lt;\/div&gt;\n &lt;ul&gt;\n  &lt;li&gt;&lt;a href=\"http:\/\/example.com\"&gt;Example&lt;\/a&gt;&lt;\/li&gt;\n &lt;\/ul&gt;\n&lt;?php endif; ?&gt;\n&lt;\/div&gt;\n<\/code><\/pre>\n\n<p>That's it. Your HTML markup is taken care of.<\/p>\n\n<p>Well, mostly taken care of. The default <code>before_widget<\/code> is a little bit more than\njust <code>&lt;li&gt;<\/code>. It includes an id and class. Well, sort of, but this is where it gets\ncomplicated. The default <code>before_widget<\/code> includes sprintf directives <code>%1$s<\/code> and <code>%2$s<\/code>,\nwhich are replaced by the id and class, respectively. The id is generated by\nsanitizing the widget name (which is why you should name your widget carefully:\nyou don't want duplicate id's in one HTML document!) and the class is generated\nfrom the widget's callback. This ensures all Text and RSS widgets, for instance,\nhave unique id's and similar classnames. Additionally, there is a \"widget\" class\nfor each widget.<\/p>\n\n<p>So, if you want your theme to be most flexible you should use this instead of\nthe empty strings shown above:<\/p>\n\n<pre><code>        'before_widget' =&gt; '&lt;div id=\"%1$s\" class=\"widget %2$s\"&gt;',\n        'after_widget' =&gt; '&lt;\/div&gt;';\n<\/code><\/pre>\n\n<p>Now your HTML markup is REALLY taken care of.<\/p><\/dd>\n<dt>The Seach Widget is ugly.  I want my theme's original search box as a widget.<\/dt>\n<dd><p>That's not a question, but it is a frequently formed comment, so we'll respond anyway.<\/p>\n\n<p>The widgets are CSS-selectable so that you can style them very specifically.\nHowever, the markup might not be to your liking. Many themes will look better\nif they supply their own widgets to replace some of the basic widgets, such as\nSearch and Meta. It's usually best to copy the existing markup from sidebar.php\ninto a new widget in functions.php, then use the registration functions to\nreplace the standard widget with the custom one.<\/p>\n\n<p>You can do this with any part of the theme's sidebar, or all of them. Here's an\nexample of how to do this:<\/p>\n\n<pre><code>function widget_mytheme_search() {\n?&gt;\n    &lt;&lt; PASTE YOUR SEARCH FORM HERE &gt;&gt;\n&lt;?php\n}\n\nif ( function_exists('register_sidebar_widget') )\n    register_sidebar_widget(__('Search'), 'widget_mytheme_search');\n<\/code><\/pre><\/dd>\n<dt>Great, I have the HTML markup looking good, but it looks awful in the browser!<\/dt>\n<dd><p>From questions, to statements, to exclamations.  You'r getting pretty antsy, aren't you?<\/p>\n\n<p>But, yeah, we knew that would happen. Your theme was probably written before widgets\nwere born so the author didn't know she should make the stylesheet flexible\nenough to handle new markup in the sidebar. If you know some CSS, you should be\nable to handle the problems with a few new rules at the end of your stylesheet.\nLook in your blog's markup for the selectors (id and\/or class) belonging to each\nwidget you want to style.<\/p>\n\n<p>If CSS is a mystery to you, we regret that we can't offer you any help. As much\nas we'd like to help you with this, it just isn't possible due to the wild\nvariations of themes. Contact your theme's author and ask her to update the\ntheme for better compatibility with widgets.<\/p><\/dd>\n<dt>I'm a theme author.  What's with all this email asking me to update my theme?<\/dt>\n<dd><p>You should be happy they like your theme well enough to contact you rather than\nswitch to somebody else's themes. Well done on making users happy! We're making\nthis plugin available now to see how the WordPress community likes it and to\ngive people a chance to write widgets. If all goes well, this feature will be\nintegrated into the standard WordPress distribution and any themes that don't\nsupport widgets will, if you believe our crystal ball, become very unpopular\nvery fast.<\/p>\n\n<p>We're sorry if that seems threatening. It hurt us more than it hurt you.<\/p><\/dd>\n<dt>This widget thing seems mighty powerful.  What else can I do with it?<\/dt>\n<dd><p>You have no idea how glad we are that you asked that. Here are a few ideas:<\/p>\n\n<ul>\n<li>Write a theme that includes a special widget to set it apart from the others.<\/li>\n<li>How about this for a special widget: a WordPress loop to show asides.<\/li>\n<li>Register a replacement widget that buffers the original widget and transforms\nit somehow.<\/li>\n<li>Remember that a \"sidebar\" is really just a name for a list. It can be\ndisplayed vertically or horizontally.<\/li>\n<li>Remember that a \"widget\" is really just a name for a configurable code\nsnippet. It can be invisible or it can be absolutely positioned.<\/li>\n<li>Use the id and class attributes of any or all widgets in scripts to animate\nyour sidebar.<\/li>\n<li>Heck, use script.aculo.us or dbx (included with WordPress) to make your\nwidgets draggable or even collapsible. Ain't scripting sweet?<\/li>\n<li>Remember that the widget control API is just for convenience. You can always\nset up your own admin page instead. <\/li>\n<li>Support your users and get feedback so you can improve your widget. Put a link\nto your email or your site at the bottom of your widget control.<\/li>\n<li>Send a link to your widgets to widgets@wordpress.com for review. We might put\nthem up for everyone to use. You could be internet famous.<\/li>\n<\/ul><\/dd>\n<dt>I have a theme with more than one sidebar.  How do I make them all dynamic?<\/dt>\n<dd><p>Oh, that's easy. Instead of <code>register_sidebar()<\/code> you should use <code>register_sidebars(n)<\/code>\nwhere <code>n<\/code> is the number of sidebars. Then place the appropriate number in\nthe <code>dynamic_sidebar()<\/code> function, starting with 1. There are several ways to dse\nthese functions but they aren't all documented here. You can even give your sidebars\nnames rather than numbers, which lets you maintain a different set of saved sidebars\nfor each theme. But if you need to know so much about the plugin, why aren't you\nreading the source code?<\/p><\/dd>\n<dt>Thanks for this plugin!  Blogging is even more fun now!  How can I repay you?<\/dt>\n<dd><p>Aww, you're welcome. Just keep on blogging and encourage others to blog, too.\nAlso, encourage people to develop new widgets. Maybe they'll accept donations\nfor their work.<\/p><\/dd>\n\n<\/dl>","raw_excerpt":"Adds &quot;Sidebar Widgets&quot; panel under Presentation menu","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/47590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=47590"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/skeltoac"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=47590"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=47590"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=47590"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=47590"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=47590"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=47590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}