How to get class from widget area

Sidebars are stored in a global variable named $wp_registered_sidebars. if ( ! function_exists( ‘before_sidebar’ ) ) { function before_sidebar( $columns=”five” ) { global $wp_registered_sidebars; $class_name = $wp_registered_sidebars[$columns][‘class’]; // Apply the markup echo “<div id=’sidebar’ class=”$class_name” role=”complementary”>\n”; } } I assumed that $columns contains the sidebar ID. The value passed into before_sidebar() is the name value … Read more

“Widgets” menu doesn’t appear

Another difference between those servers which was actually the problem was that the live server where the issue occurred had been installed via fantastico. After manually reinstalling it, everything was fine.

Widget select option not saving

This line $type = isset( $instance[‘type’] ); will set $type to either true or false which never matches the string you check for later: foreach ($types as $option) { echo ‘<option value=”‘ . $option . ‘” id=”‘ . $option . ‘”‘, $type == $option ? ‘ selected=”selected”‘ : ”, ‘>’, $option, ‘</option>’; } You need … Read more

Add custom data (field) to sidebar widgets for later display

Crude code. I have never tried this but I can get you part of the way there. Add a field… add_action( ‘in_widget_form’, function ($instance) { echo ‘<input type=”text” value=”c00l” />’; return null; }, 1 ); And there is a hook that runs on settings update. add_filter( ‘widget_update_callback’, function($instance, $new_instance, $old_instance, $this) { var_dump($instance, $new_instance, $old_instance, … Read more

call widget from within shortcode

The second parameter of this function (the_widget) is an array with some arguments that defines what are the variables of this instance of the Widget, when you are outside of a Sidebar “loop”, you have to pass those manually, instead of getting them from the database. I’ve found the GitHub Repo for this plugin, and … Read more

Display custom widget value in header.php

The Codex is your friend. There’s a the_widget() function for that. <?php the_widget( ‘MY_Widget’, $instance, $args ); ?> Refer to the Codex entry for values for $instance and $args. $instance = array( ‘title’ => ‘Some Title here’, ‘name’ => ‘Some Name here’, ‘show_info’ => true ); $args = array( ‘before_widget’ => ”, // Your value … Read more

Widget : html 2 dimensional array doesn’t work

Ok, with a quick dirty hack I have achieve my goal : Instead of myCollection[id][myField] I give to the get_field_name‘s function something like this : collection][id][field. So the generated code became : name=”widget-pricetable-ibsciss-widget[2][box][1]Widget : html 2 dimensional array doesn’t work” And my array just look perfect now : array(3) { [“title”]=> string(12) “Global title” [“box”]=> … Read more

What conditional to use for dynamic sidebar check?

dynamic_sidebar() produces sidebar output. So case by case: Checking if sidebar is active is pointless because otherwise it would just do nothing anyway. This check is useful if you need to perform it elsewhere for something different and/or more extensive than just calling it. Calling it just works. << so this is what you want … Read more