How to edit widgets in WordPress

The WordPress Widgets API is how various widgets are created and sidebars registered. When creating a new widget there are variables that can be added to any widget. Those get their value from the register_sidebars arguments. args (string/array) (optional) Builds Sidebar based off of ‘name’ and ‘id’ values. Default: None name – Sidebar name. id … Read more

Get number of widgets in sidebar

After some research and based on the answer from Eugene Manuilov I made a function that adds custom classes to widgets in a specific sidebar (‘sidebar-bottom’ in my case) based on the number of widgets set in that sidebar. This will suit perfectly in horizontal sidebars and themes based on twitter bootstrap that need spanX … Read more

Code for Recent Posts Widget

The default Recent Posts Widget code is in includes/default-widgets.php but you should not be hacking Core code. Copy that function to your theme’s functions.php, rename it, and create your own customized widget.

Is there any way to dynamically alter widget titles?

You can use the widget_display_callback (fired, predictably, just prior to displaying a widget 🙂 ). add_filter(‘widget_display_callback’,’wptuts54095_widget_custom_title’,10,3); function wptuts54095_widget_custom_title($instance, $widget, $args){ if ( is_single() ){ //On a single post. $title = get_the_title(); $instance[‘title’] = $instance[‘title’].’ ‘.$title; } return $instance; } The $widget argument is an object of your widget class, and so $widget->id_base will contain the … Read more

Add class to before_widget from within a custom widget

Aha, so the $before_widget variable is a string representing div element: <div class=”widget my” id=”my-widget-1″> . So I checked the $before_widget for the “class” sub-string and added my $widget_width value to it. The code is from my custom widget file: function widget( $args, $instance ) { extract( $args ); … //other code $widget_width = !empty($instance[‘widget_width’]) … Read more

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