Tag Info

Hot answers tagged

4

You just need to use the alternate syntax for foreach. From the php manual: The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. There are two syntaxes: foreach ...


4

As alluded to by @Michael in the comments, the CSS classes for widgets depend on the sidebar they're in more than the widget themselves. Those widget-specific CSS classes can be useful, but not when you're trying to style every widget. It sounds like you may be able to use a normal element selector that targets anything in your sidebar, though I'm unclear ...


3

Instead of calling get_sidebar() call get_sidebar( 'somethingelse' );. It will attempt to load sidebar-somethingelse.php and if that doesn’t exist it will load sidebar.php. You can then modify the sidebar-somethingelse.php to load a different sidebar etc I strongly recommend you look up how the template hierarchy works.


2

I ran into this problem with one of my plugins, and am deeply indebted to this article for pointing me in the right direction. The key is that the third parameter you get in the callback includes the widget's basename (derived from its class). I used a slightly different AJAX function than the example you linked to, but here's what I came up with: ...


1

The default widgets do not offer any hooks for that. You have to replace the default widget and add your field to the new class. The other option would be using JavaScript to insert the field, and a filter for 'update_option_widget_' . $widget->id_base to save the value. I think the separate class is the cleaner approach.


1

Yes, you can separate your code and markup into multiple files. Be aware of scope issues when you use include, but done carefully it should be no problem. Since you are in WordPress and building a theme, I would suggest get_template_part over a raw include. In many ways, "chopping" up your theme files is what get_template_part is for-- well, at least it is ...


1

You can filter sidebars_widgets and remove the widget you don’t need. Example with a search widget; uncomment the debug code to find the correct identifier. if ( ! is_admin() ) add_filter( 'sidebars_widgets', 'remove_specific_widget' ); function remove_specific_widget( $widgets ) { if ( ! is_single( 402 ) ) // Post ID, title, slug, or array of ...



Only top voted, non community-wiki answers of a minimum length are eligible