Articles of widgets

Is It Possible to Restore Accidentally Deleted Widgets?

I accidentally deleted the widgets without dragging it to the inactive widgets section. I have a backup of all the files and the database but i have changed many things on the site other than the widgets. Can I only restore the widgets?

How to determine if post has widget content?

I’ve got a registered sidebar called “my-header” that affects the absolute positioning of elements below it in the markup. So I need to execute a query in header.php to determine if the sidebar is present for the current post, and write out a class identifier to my theme’s body tag. I’ll use this css class […]

wp_count_posts, wp_count_terms and wp_count_comments for specific user?

Is there a way for the functions wp_count_posts, wp_count_terms and wp_count_comments to return their results only for a specific user, possibly by using a user’s ID? I’m making a custom “Right Now” dashboard widget for a custom post type and I need it to show data for the current user only, not for the whole […]

Widgets not expanding on wordpress 3.3 widget dashbord

I updated to WordPress 3.3 (manual update) and cleaned browser cache. Widgets dashbord stop working when tring to expand dynamic sidebars for custom theme when it works for previous wordpress 3.2 installation (using register sidebar on functions.php) I have tried to install Hotfix 0.8 exension and now it works for twentyten theme but not for […]

Full width layout for custom post type pages

I’m trying to remove a widget area called ‘Primary’ from a certain page on a site. This is the function where I manage the sidebars: //ADD CATEGORIES IN SIDEBAR OF SINGLE POST TYPE add_action( ‘genesis_sidebar’, ‘add_mysite_sidebar’ ); function add_mysite_sidebar() { if( get_post_type() == ‘post’ ){ dynamic_sidebar( ‘News Categories’ ); } else if( get_post_type() == ‘events’ […]

javaScript in <head> section of WP API

How do I place the following javaScript in the <head> section of the WordPress Widgets API menu screen? <script type=”text/javascript”> jQuery(window).load(function() { jQuery(“#logocheckbox”).change(function() { jQuery(“#logocheckboxdiv”).fadeToggle(“slow”); }); }); </script>

Passing $this->get_field_name() to javascript

I’ve tried doing this one of two ways: In the form method of my Widget class (which extends WP_Widget), I have the following snippet, which sets a global javascript variable: if( $instance ) : ?> <script type=”text/javascript”> window.widget_order_name = “<?php echo $this->get_field_name( ‘order’ ) ?>”; </script> <?php endif; In the widget admin markup, I also […]

How can I delete all inactive widgets?

I want to cleanup all inactive widgets. I tried following snippet as suggested by this answer Script to remove all inactive widgets?. $sidebars_widgets = get_option( ‘sidebars_widgets’ ); $sidebars_widgets[‘wp_inactive_widgets’] = array(); update_option( ‘sidebars_widgets’, $sidebars_widgets ); I also tried deleting option sidebars_widgets directly from the options table. But after page is refreshed, old value is restored with […]

How to check if a shortcode is being executed in a widget or post

I am creating a feature for my website using a WordPress shortcode. The shortcode is displays an HTML table that contains certain data. I have enabled the short code for widget/sidebar and it is working fine in the widget. The only problem is that my designer has created two different styles; one for post and […]

Custom Widget form function common elements

I am writing a set of custom widgets, all of which share a common 18 lines of code in the form() function, which looks like this: <div class=”common-section”> <input type=”hidden” class=”inputbox” name=”something” /> <?php $choices = [ ‘first’ => array(‘red’,’orange’,’blue’), ‘second’ => array(‘red’,’white’,’blue’), ‘third’ => array(‘green’,’black’,’white’) ]; ?> <?php foreach($choices as $colorset => $colors) : […]