How to add author details in the post sidebar?

global $authordata; This variable contains the current post’s author data. From an author data widget I have written: global $authordata; if ( ( is_singular() or is_author() ) and is_object( $authordata ) and isset ( $authordata->ID ) ) { return $authordata->ID; } To get the link to the author archive: get_author_posts_url( $authordata->ID ); Update Here is … Read more

Where to find the source code of a widget?

The default widgets are defined in wp-includes/default-widgets.php. To find specific code search the Codex or use queryposts.com. The best tool is your IDE (integrated development environment). All IDEs offer a full text search in a set of files. Here a screen shot from Eclipse PDT As you can see it is really flexible – and … Read more

How to add color picker to widgets?

Here is the code I used for one of my projects: <?php function load_color_picker_style() { wp_enqueue_style( ‘wp-color-picker’ ); } add_action(‘admin_print_scripts-widgets.php’, ‘load_color_picker_script’); add_action(‘admin_print_styles-widgets.php’, ‘load_color_picker_style’); ?> ///Javascript jQuery(document).ready(function($){ function updateColorPickers(){ $(‘#widgets-right .wp-color-picker’).each(function(){ $(this).wpColorPicker({ // you can declare a default color here, // or in the data-default-color attribute on the input defaultColor: false, // a callback to fire … Read more

Programmatically edit the text of a widget

I guess you want to locate the widget by it’s title, so you can try this function: /** * Update a widget text located by it’s title * * @see https://wordpress.stackexchange.com/a/155518/26350 * * @param string $search_title * @param string $new_text * @param boolean */ function wpse_155046_update_widget_text_by_title( $search_title, $new_text ) { // Get all data from … Read more

Filter Widget Title Wrap

The filter to do this is dynamic_sidebar_params also see this tutorial on this filter at ACF’s site (even if you don’t use ACF). function prefix_filter_widget_title_tag( $params ) { $params[0][‘before_title’] = ‘<h2 class=”widget-title widgettitle”>’ ; $params[0][‘after_title’] = ‘</h2>’ ; return $params; } add_filter( ‘dynamic_sidebar_params’ , ‘prefix_filter_widget_title_tag’ );

How wp_cache is supposed to work, and does it help with performance?

In WordPress v2.5+ the object cache is not persistent. It will save things in memory, but for persistent caching across page loads you will need a plugin see here: http://codex.wordpress.org/Class_Reference/WP_Object_Cache#Persistent_Caching Alternatively, use transients, which are persistent. The identifier must be 45 or less characters long, but the data attached to that identifier can be longer. … Read more

How do I rebind event after widget save

WordPress provides callbacks for widgets interactions. You’re seems interested in two of them: widget-added, widget-updated Usage example: jQuery(document).on(‘widget-updated’, function(e, widget){ // do your awesome stuff here // “widget” represents jQuery object of the affected widget’s DOM element });

Loop through widgets in sidebar

The registered widgets in your sidebar-1 might be [sidebar-1] => Array ( [0] => categories-2 [1] => archives-4 [2] => recent-comments-4 [3] => calendar-2 [4] => search-2 [5] => archives-2 [6] => text-4 [7] => recent-posts-2 [8] => nav_menu-2 ) If you got for example the calendar-2 widget, then from: print_r( $GLOBALS[‘wp_registered_widgets’][‘calendar-2’] ); you will … Read more

Modify recent post sidebar to show post thumbs with out plugins

HERE IS THE SOLUTION /** * Extend Recent Posts Widget * * Adds different formatting to the default WordPress Recent Posts Widget */ Class My_Recent_Posts_Widget extends WP_Widget_Recent_Posts { function widget($args, $instance) { if ( ! isset( $args[‘widget_id’] ) ) { $args[‘widget_id’] = $this->id; } $title = ( ! empty( $instance[‘title’] ) ) ? $instance[‘title’] : … Read more