Questions tagged [widgets]

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

Filter by
Sorted by
Tagged with
99 votes
7 answers
18k 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 ...
fuxia's user avatar
  • 106k
95 votes
3 answers
43k views

Between functions.php (theme), 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 ...
pixeline's user avatar
  • 2,837
71 votes
4 answers
38k 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 '...
Marlun's user avatar
  • 821
25 votes
2 answers
8k 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 ...
Howdy_McGee's user avatar
  • 20.5k
21 votes
2 answers
6k 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 ...
Tom J Nowell's user avatar
  • 58.2k
21 votes
1 answer
23k views

How to include checkbox in widget backend form?

I'm trying to include a checkbox in my widget back end. But I cannot get the value (on or off) after the user submits it. I thought the value would be stored in "esc_attr( $check )" (as it is when ...
Lisandro Vaccaro's user avatar
19 votes
3 answers
18k views

How can I modify the WordPress default widget output?

I don't want to style the default widget with only CSS. I want to display the default 'Categories' widget content with my own HTML structure. Is there available any filter or hook to do that?
Eh Jewel's user avatar
  • 845
17 votes
4 answers
16k 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 http://...
Lemon Bacon's user avatar
  • 1,161
17 votes
4 answers
8k 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 ...
Jukov's user avatar
  • 423
17 votes
3 answers
7k 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, ...
Ian Dunn's user avatar
  • 4,817
16 votes
2 answers
15k views

Give Editor Access To Sidebar

I want to give the Editor Role access to editing the sidebar and it's contents. I have a text widget in there and in order to edit this text widget the user needs to be an admin - this sucks. How do I ...
Howdy_McGee's user avatar
  • 20.5k
15 votes
4 answers
6k 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 ...
onetrickpony's user avatar
  • 13.6k
15 votes
2 answers
6k 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 ...
Jared's user avatar
  • 3,835
15 votes
2 answers
16k 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 ...
pixeline's user avatar
  • 2,837
14 votes
1 answer
21k 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 ...
N2Mystic's user avatar
  • 3,173
13 votes
5 answers
11k 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 ...
JohnnyBizzle's user avatar
13 votes
3 answers
2k 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 ...
Mark Jeldi's user avatar
12 votes
1 answer
58k views

Where is the content of widgets stored in mysql table

I have the cPanel access to a website but no wordpress login info. So I wants to change a widget content in the website. How can I change it through phpmyadmin. Where are that widgets sidebar data ...
Libin's user avatar
  • 276
12 votes
5 answers
37k views

Hide specific categories from category widget

I'm trying to hide a large amount of categories from my category widget. I've tried a few plugins but none of them seem to want to let me use the dropdown option. I looked into the ...
FranticJ3's user avatar
  • 169
12 votes
2 answers
9k 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 ...
Ole Henrik Skogstrøm's user avatar
11 votes
4 answers
11k views

Add a custom walker to a menu created in a widget

I know how to add a Walker to a custom menu created by the theme (menu named primary in this example), but how can I target a menu thats created in a widget with the default wordpress custom menu ...
amy's user avatar
  • 385
11 votes
2 answers
12k 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 ...
jay's user avatar
  • 175
11 votes
4 answers
35k views

How to get post ID of the current page/post inside a widget?

I'm trying hard to get the post ID of the current post/page inside a widget class but doesn't work, I know there's get_the_ID() and some other options but not a single works inside a widget. Here's my ...
Faizan Ali's user avatar
11 votes
3 answers
2k 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 to ...
Lea Cohen's user avatar
  • 1,640
10 votes
5 answers
19k 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 ...
dashaluna's user avatar
  • 2,072
10 votes
7 answers
21k 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', '...
MBraiN's user avatar
  • 223
10 votes
3 answers
5k 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 ...
cannyboy's user avatar
  • 1,033
10 votes
1 answer
2k 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 ...
Pierre's user avatar
  • 1,014
10 votes
2 answers
2k 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 ...
Dan 's user avatar
  • 464
10 votes
1 answer
582 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', '...
onetrickpony's user avatar
  • 13.6k
9 votes
4 answers
46k views

How do register_sidebar() and get_sidebar() work together?

Disclaimer: I am brand spanking new to WP. I am using the Starkers HTML5 framework theme. In the functions.php I see this code: function starkers_widgets_init() { // Area 1, located at the top ...
jessegavin's user avatar
  • 3,416
9 votes
4 answers
10k views

How to enqueue script if widget is displayed on page?

I created a widget that uses a jquery plugin, and I used is_active_widget to enqueue the script, it's working fine but it's also including the script even on pages that doesn't show this widget. so is ...
Pierre's user avatar
  • 1,014
9 votes
2 answers
7k 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 ...
Wyck's user avatar
  • 17.9k
9 votes
1 answer
20k 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 ...
kschaeffler's user avatar
9 votes
3 answers
2k views

Can the new 4.8v text widget visual editor be removed?

Can the new 4.8 widget visual editor in the default text widget be unhooked or removed and the widget restored to the pre-4.8 editor style? I don't need or want the visual editor in widgets; I use ...
BlueDogRanch's user avatar
9 votes
4 answers
356 views

Plugin upgrading: Widget settings

I have tried doing some research on this but haven't found anything solid yet. I have a plugin I am working on and between the last version and the new version we made some updates to the widget that ...
Nick Young's user avatar
8 votes
2 answers
43k 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!
Astoria's user avatar
  • 317
8 votes
4 answers
8k views

Get number of widgets in sidebar

How can I get the number of widgets that are active on a specific sidebar? Is there a core function for this? I want to add a class to each widget on a sidebar based on how many of them are displayed....
nautilus7's user avatar
  • 341
8 votes
3 answers
7k views

Text Widget creates a <li>

I've got a basic text widget and, outside the standard <div class="textwidget"> wrapper there is a <li id="text-5" class="widget widget_text"> (which I have not added when creating the ...
Snowcrash's user avatar
  • 317
8 votes
7 answers
7k 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 '...
Frank N's user avatar
  • 455
8 votes
1 answer
3k views

Using wp_category_checklist in a widget

I'm trying to use wp_category_checklist in a widget to display a list of checkboxes which, when saved, remain ticked. I'm having awful trouble at the moment getting them to save, as as far as I know ...
Rhys Wynne's user avatar
8 votes
5 answers
5k views

Sharing Dynamic Sidebars across Multisite Blogs

I'm trying to find away to retrive a dynamic sidebar from one blog and print it on another blog in the same install of Wordpress Multisite. I have tried switch_to_blog($blog_id); dynamic_sidebar($...
Timothy Wallis's user avatar
8 votes
3 answers
3k 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 ...
Jan Fabry's user avatar
  • 30.4k
8 votes
1 answer
208 views

Can a widget in the Customizer be “single-use” (i.e. disabled after 1 instance has been added)?

I’m on a nightly quest to build a custom single-use widget. As soon as one instance of it has been added to a sidebar panel in the Customizer, its control on the Available Widgets panel should be ...
glueckpress's user avatar
7 votes
3 answers
23k views

check if registered sidebar is active & has widget content

I'd like to check if a registered sidebar has widget content - but can't seem to find a WP function for this - is_active_widget checks if it has content, but not if it exists or not. function ...
Q Studio's user avatar
  • 2,506
7 votes
1 answer
14k views

Get a list of all Widgets registered in WordPress admin widgets-area

I'm trying to disable a couple standard widgets in my theme functions.php. Therefore I wrote this little function, which works well: function my_widget_ctrl() { unregister_widget('...
Tobias's user avatar
  • 71
7 votes
2 answers
3k 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 ...
Yoav Kadosh's user avatar
7 votes
4 answers
47k 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?
itsme's user avatar
  • 195
7 votes
2 answers
49k views

How to edit widgets in WordPress

In the Appearance -> Widgets menu there is a list of widgets that you can drag and drop to show in the sidebar. Where is the HTML/PHP code for these custom widgets? I've been on WordPress's Function ...
AlexMorley-Finch's user avatar
7 votes
6 answers
11k 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 ...
N2Mystic's user avatar
  • 3,173

1
2 3 4 5
42