widget_title │ filter-hook │ WC 2.6.0

This is a WordPress - widget_title hook. The plugin just uses it.

Allows you to change a widget title on the front end.

Usage

add_filter( 'widget_title', 'wp_kama_widget_title_filter', 10, 3 );

/**
 * Function for `widget_title` filter-hook.
 * 
 * @param string $title    The widget title.
 * @param array  $instance Array of settings for the current widget.
 * @param mixed  $id_base  The widget ID.
 *
 * @return string
 */
function wp_kama_widget_title_filter( $title, $instance, $id_base ){
	// filter...
	return $title;
}
$title(string)
Widget title.
$instance(array)

Current widget settings. For example, depending on its settings, the Categories widget may contain the following data:

Array
(
	[title] => Categories
	[count] => 0
	[hierarchical] => 1
	[dropdown] => 1
)
$id_base(string)
Widget ID specified in the widget class constructor. For example, the Categories widget has id = categories, while the Recent Posts widget has id = recent-posts.

Examples

#1 Change only the titles of Categories widgets

Do the same as in the first example, but only for Categories widgets.

/**
 * Changes the title of every Categories widget.
 *
 * @param string $title
 * @param array  $instance
 * @param string $id_base
 *
 * @return string
 */
function filter_widget_categories_title( $title, $instance, $id_base ) {
	if ( 'categories' == $id_base ) {
		$title = "<span class='my-custom-class'>$title</span>";
	}

	return $title;
}

add_filter( 'widget_title', 'filter_widget_categories_title', 10, 3 );

#2 Change the title of every widget

Wrap every widget title in a span tag with a custom CSS class.

/**
 * Changes the title of every widget.
 *
 * @param string $title
 *
 * @return string
 */
function filter_all_widget_title( $title ) {
	return "<span class='my-custom-class'>$title</span>";
}

add_filter( 'widget_title', 'filter_all_widget_title' );

#3 Change the title of every Categories widget displayed as a dropdown

/**
 * Changes the title of every Categories widget displayed as a dropdown.
 *
 * @param string $title
 * @param array  $instance
 * @param string $id_base
 *
 * @return string
 */
function filter_widget_categories_title( $title, $instance, $id_base ) {
	if ( 'categories' == $id_base && ! empty( $instance['hierarchical'] ) ) {
		$title .= ' as a dropdown';
	}

	return $title;
}

add_filter( 'widget_title', 'filter_widget_categories_title', 10, 3 );

Where the hook is called

WC_Widget::widget_start()
widget_title
WC_Widget_Brand_Thumbnails::widget()
widget_title
WC_Widget_Brand_Nav::widget()
widget_title
woocommerce/includes/abstracts/abstract-wc-widget.php 165
$title = apply_filters( 'widget_title', $this->get_instance_title( $instance ), $instance, $this->id_base );
woocommerce/includes/widgets/class-wc-widget-brand-thumbnails.php 113
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->woo_widget_idbase );
woocommerce/includes/widgets/class-wc-widget-brand-nav.php 117
$title        = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );

Where the hook is used in WooCommerce

Usage not found.