Sidebar widgets – dynamic CSS : problem with widget-title

Not a good solution… but is a solution: using jquery. register_sidebar( array ( ‘name’ => ‘Left Widget Area’, ‘id’ => ‘primary_widget_area’, ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”><div class=”widget-title”></div><div class=”widget-content”>’, ‘after_widget’ => ‘</div></li><!– .widget –>’, ‘before_title’ => ‘<span class=”invisible-title” data-widget=”%1$s” style=”display:none;”>’, ‘after_title’ => ‘</span>’, ) ); and the JS jQuery().ready(function($) { $(‘.invisible-title’).each(function() { var title = … Read more

Conditional widget_form_callback

You need to get the array of sidebars and their widgets with wp_get_sidebars_widgets(), then check if the current widget is in the ‘footer’ sidebar: $sidebars = wp_get_sidebars_widgets(); if ( in_array( $widget->id, $sidebars[‘footer’] ) ) { /* Display form fields here */ } Update: There is one caveat to this, which you have discovered. The widget … Read more

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

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

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

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

Why would apply_filters return a non-empty string, when the value returned is empty?

The problem is in the theme you’re using. This has been reported before: https://core.trac.wordpress.org/ticket/21430 Seems that Elegant Themes don’t like their widgets to not have titles. So they have a function called “et_widget_force_title” which changes blank titles into titles with a single space. In case of doubt, always try disabling plugins and switching to the … Read more

Random sidebar/widget background

Place the following code above the DOCTYPE in header.php: <?php $bg = array(‘bg-01.jpg’, ‘bg-02.jpg’, ‘bg-03.jpg’, ‘bg-04.jpg’, ‘bg-05.jpg’, ‘bg-06.jpg’, ‘bg-07.jpg’ ); // array of filenames $i = rand(0, count($bg)-1); // generate random number size of the array $selectedBg = “$bg[$i]”; // set variable equal to which random filename was chosen ?> Now place this code within … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)