Widgets are configurable elements used to dynamically build sections of a WordPress theme.

learn more… | top users | synonyms (2)

29
votes
4answers
6k views

Where to put my code: plugin or functions.php?

Is there an easy to understand scheme to decide what kind of code belongs to a plugin or the theme’s functions.php? There are many cases and many debates about that topic, mostly because there are ...
25
votes
4answers
7k views

Programmatically add widgets to sidebars

I would like to programmatically add widgets to my two sidebars that I've got. I couldn't find any official way of doing it? I started looking in the database. I've found that it's the ...
20
votes
2answers
6k views

Between functions.php, widgets and plugins, which is loaded first?

Customer asks if a specific carousel plugin he uses can be widgetized. That means i should create a widget inside functions.php which calls the plugin's function. That means that the plugin's code has ...
16
votes
2answers
4k views

Wordpress 3.8 - Dashboard 1 Column Screen Options

With the new Wordpress 3.8 under Screen Options they seem to have misplaced the "Columns" feature where you could put your widgets into 1 Column, 2 Columns, 3 Columns, or 4 Columns. My question is how ...
12
votes
2answers
720 views

Conditionally enqueue a widget's script/stylesheet in HEAD (only when present on page!)

I've been trying to load scripts and styles for a WordPress widget with the following conditions... The scripts MUST load in the HEAD (else they break). The scripts must ONLY load when the widget ...
11
votes
4answers
3k views

Limit number of Widgets in Sidebars

If I use a custom widgetized area (for example footer) where there is only a limited number of spots for widgets (by design), can I limit the number of widgets the user may include in that specific ...
11
votes
3answers
2k views

How Can I Add the “Insert From URL” Tab to a Custom 3.5 Media Uploader?

I've inserted a WP 3.5 media uploader into a widget by running this JavaScript when a button is clicked on: var frame = wp.media( { title : 'Widget Uploader', multiple : false, ...
10
votes
3answers
1k views

changing wp-admin/widgets.php

We want to design the widgets page in the admin panel a little differently, mainly in order to help the site administrator understand where each widget will appear in the site: For that, we need ...
10
votes
1answer
2k views

Custom Widget function in Plugin not working?

I took a code straight out of one of my themes I created, and it's a list of all 50 states in an unordered list packed into a widget you can just drag and drop on the sidebar. The problem is, when I ...
10
votes
1answer
407 views

Limit the number of inactive widgets

I'm trying to restrict the number of widgets from the "wp_inactive_widgets" sidebar to maximum 10, because the widgets admin page is incredibly slow: add_filter('pre_update_option_sidebars_widgets', ...
9
votes
3answers
8k views

Loading scripts only if a particular shortcode or widget is present

I needed a way to filter a page/posts content before it was loaded so I could add scripts to the header if a specific shortcode was present. After much searching I came across this on ...
9
votes
2answers
552 views

Executing Javascript When a Widget is Added in the Backend

I have widgets that have javascript controls attached to them. If the widget is present when the widget admin page loads, the controls work correctly. When I add a new widget, they do not work ...
9
votes
3answers
2k views

Update widget form after drag-and-drop (WP save bug)

I've posted a bug-report about this a few months ago (on WordPress trac (Widget Instance Form Update Bug)) and I thought I'd try writing about it here too. Maybe someone has a better solution to this ...
8
votes
3answers
3k views

Custom Post Type Data in Sidebar widgets?

(note: this question was originally about Custom Fields, but @MikeSchinkel had a better solution involving Custom Post Types) On my site I have several pages which I want to show the same data in the ...
7
votes
7answers
3k views

Individual Widgets per Page

In my (page-only, no posts) Wordpress site I have a number of static blobs in need to put in a sidebar. We could call/tream thoses 'blobs' as widgets. At least they'll have a fixed html content, like ...
7
votes
3answers
2k views

Limit widget to certain sidebar?

I have multiple "sidebars", but not all of them are the same size. Not all widgets fit in all sidebars (for example, I have a "footer sidebar" where the client can place custom widgets, but they are ...
6
votes
2answers
871 views

What is the correct way to build a widget using OOP

I am working on a simple search form widget, with a built in autocomplete capability (You can download the current version here). The plugin is working, but I am currently rewriting all the code using ...
6
votes
1answer
631 views

Extend WordPress 3.8 Site Activity Dashboard Widget to include more comments

The new Site Activity dashboard widget defaults to showing 5 comments. I'd like to show 10. I can see the code in core /wp-admin/includes/dashboard.php where it calls the function ...
6
votes
1answer
1k views

What is the difference between wp_register_sidebar_widget and register_widget?

What's the difference between them and when should we use each one ? I'm using wp_register_sidebar_widget right now and it's working fine but I've seen a lot of tutorials online on how to create a ...
6
votes
3answers
1k views

How Do I Add Custom CSS To Only Certain Widgets

I have a standard dynamic sidebar using register_sidebar and dynamic_sidebar and I need the last widget in the sidebar (which will not have a set number of widgets) to have a distinct class ...
6
votes
3answers
307 views

Author template, filter sidebar widgets by author?

I'd like to be able to filter my sidebar widgets (tag cloud, category, archive) to only show those tags/categories/months that apply to a given author on the author template. What is the correct way ...
6
votes
1answer
5k views

How to load Widget javascript + css files only if used?

I'd like to keep the javascript and css styles used by my widget inside their own files (and not add them to the theme). But i can't seem to get wordpress to add them when the widget is actually used ...
6
votes
1answer
1k views

Adding Widget form fields dynamically

I am trying to add form field to a WordPress widget dynamically. So if the user want to add another date to an event they can click a button to get more fields. The question is: How do save newly ...
6
votes
2answers
285 views

How can I use the built in Wordpress “browse link” functionality?

I'm coding a widget and I'd like the user to be able to pick a link like you can when editing a regular posts or page (when you click on the little link icon and you get the AJAX search functionality ...
5
votes
4answers
4k views

Using widget options 'outside' the widget

I want to save some parameters in the widget options which are then passed into another page. The widget is a form which calls a webservice. The options I want to pass are the authentication for the ...
5
votes
3answers
4k views

Add class to before_widget from within a custom widget

I have a simple custom widget that asks for its width (that is used later in the front end). The width field is a select dropdown, so a user have predefined options. I will have many instances of my ...
5
votes
2answers
1k views

What is the quickest way to make a widget?

I have some PHP code that I would like to pull out of an existing page of a template, and put into a widget so I can move it around. What is the quickest way to create a widget?
5
votes
4answers
3k views

Adding a div to wrap widget content after the widget title

I'm trying to add a div to a widget's content in my dynamic sidebar. Here is the register code; register_sidebar(array( 'name' => "Sidebar1", 'id' => 'home-sidebar-1', ...
5
votes
1answer
8k views

Can I create my own “Recent Posts” widget or customize the existing one?

I'd like to enable the Recent posts widget with the ability to show a "View All" link when there are more posts than I've currently got the widget set to show. I'd also like to be able to exclude ...
5
votes
6answers
4k views

Simple rich text editor in Text widget?

I've seen a few plugins that add rich text editing to the default "Text" Widget. However, all of the ones I've tested are either too complicated (or try to do too much) or don't work properly with the ...
5
votes
1answer
124 views

Add filter to blogroll widget

I'm trying to add <i class="icon-ok"></i> before the content inside the <li> of the blogroll widget. I'm assuming that's done through the link_title filter, but I can't find a ...
5
votes
1answer
11k views

Translate widget titles using qTranslate plugin

I'm actually using the qTranslate plugin to translate my website. It works really well with everything except one thing. the titles of my sidebar widgets. Actually, to translate some words we need to ...
5
votes
1answer
665 views

Highlight custom widgets in the admin area?

I have created some custom widgets for my client to use, but I want to make them stand out amidst the fifteen or so standard widgets in the admin area. How can I do this? I have solved this problem ...
5
votes
2answers
747 views

Complex widget form UI - examples and best practices

I'm contemplating a widget with quite a number of options, which will make for a lengthy widget form. To improve the user experience with this form, I'd like to divide it into sections. I don't feel ...
5
votes
1answer
1k views

How to hide or remove unwanted widgets on Multisite installation?

I am using Multi-site installation. I don't want all the widgets appear under widgets.php on dashboard .So I tried to find a way to remove or hide unnecessary widgets . SO that the new sub-sites ...
5
votes
2answers
5k views

How to override the wordpress default widget markup

I am new to wordpress, Here i use the wordpress TwentyEleven theme, i need to customize the widget markup. It means the suppose i want to change the element 'ul' to div and add some class or id to ...
5
votes
4answers
3k views

dynamically add scripts to WP_Widget widget() method

I have a wordpress widget that has the standard outline like: class my_widget extends WP_Widget{ function my_widget(){ //do setup stuff } function form(){ //do form stuff } function ...
5
votes
1answer
107 views

Why is the $old_instance needed for the widget update function?

In the PHPdoc of the function WP_Widget::update() located under wp-includes/widgets.php it says the following: /** * ... * This function should check that $new_instance is set correctly. * The ...
5
votes
2answers
110 views

Retrieve each widget separately from a sidebar

I would like to retrieve each widget existing in a sidebar in order e.g. to mix them with posts inside the main loop. I know I can use different widget areas (sidebars) but this approach clutters the ...
5
votes
1answer
2k views

How to store widget fields data as an array?

I am creating a widget, it needs to store about 10 IDs. Right now I'm using following field method to store each of the ID in a separate field. It stores data of each field in a separately in the ...
5
votes
2answers
172 views

Prevent widgets removal

I'm building a site with a lot of widgets. They have been highly customized. Several admins/editors will have to edit these widgets when the site is live. Right now I'm scared to see a widget (and ...
5
votes
2answers
2k views

Add the sidebar/widget editor to the post edit screen?

There are (among others) two common ways of customizing the sidebar on an individual post: Create a new sidebar for the post, using code or plugins like Custom sidebars, WP Custom Sidebar, Per Page ...
5
votes
1answer
2k views

How display widget by id

I fetched widget id this way: $the_sidebars = wp_get_sidebars_widgets(); print_r( $the_sidebars['sidebar-1'] ); It shows: Array ( [0] => recent-posts-2 [1] => recent-comments-2 [2] ...
5
votes
3answers
143 views

Prevent second widget activation

Is there a way to "remove the widget from available widgets" after you've activated it once on some area? The idea is to allow user to activate only one instance of it.
5
votes
2answers
2k views

How can I get $id variable in widget's form function?

How can I get $id variable in widget's form function? According to widget's structure I see that widget function have $args as a parameter, which will be extracted in function's body. In my case i ...
5
votes
7answers
11k views

How can I add links to widget titles?

I'm using three widgets, two of them are default WP widgets (Recent Posts and Archives) and the third one is a custom widget which acts like Recent Posts but for a specific custom Post Type. My ...
4
votes
2answers
8k views

Code for Recent Posts Widget

I want to make changes to code of the Recent Posts widget – could anyone please tell me where that code is located? Thank you in advance!
4
votes
5answers
3k views

Different widgets on different page templates?

If I have a couple of different Page templates, how would I show a different collection of sidebar widgets for each of these templates? I'm using the Starkers theme as a starting point.
4
votes
2answers
2k views

Is there any way to dynamically alter widget titles?

I have a case where that are a lot of widgets in several custom sidebars. I am wondering if there is a simple way to alter the titles of each widget dynamically. Typically a widget has a title field ...
4
votes
3answers
7k views

How to add a specific widget to only 1 page?

I would like to show a widget in only one page of my site, as i can see it is not possible right? Should i add that for all my site pages or not?