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

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

Is there a way to add more tags to the tag cloud?

The tag cloud widget uses wp_tag_cloud() to display the tags, which defaults to 45 tags. Source: https://developer.wordpress.org/reference/functions/wp_tag_cloud/ One can use the widget_tag_cloud_args filter to change this number (and any other arguments passed to wp_tag_cloud(). Here’s an example: function wpse_235908_tag_cloud_args( $args ) { $args[‘number’] = 70; // the number of tags you want to display. return … Read more

Register multiple sidebars

You just need to use the alternate syntax for foreach. From the php manual: The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. … Read more

$post>ID displays wrong post ID

If i understand correctly you are trying to display a list of child pages of a page in a widget, if so then first check if you are on a page using the conditional tag is_page() then you can use $wp_query->get_queried_object_id() like t31os has pointed out so your widget display function should look like this: … Read more

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