这对我在dynamic_sidebar_params
:
/**
* Get Widget instance title or widget name as a fallback.
* Returns empty widget titles too.
*
* @param string $widget_id
* @return string Widget title or widget name
*/
function get_widget_title( $widget_id ) {
global $wp_registered_widgets;
// get instance
$instance = $wp_registered_widgets[$widget_id][\'callback\'][0];
// @see https://developer.wordpress.org/reference/classes/wp_widget/get_settings/
$settings = $instance->get_settings();
// fallback 1 – widget number can\'t be found
if ( isset( $wp_registered_widgets[$widget_id][\'params\'][0][\'number\'] ) ) {
$num = $wp_registered_widgets[$widget_id][\'params\'][0][\'number\'];
} else {
return $instance->name;
}
// nasty nesting
if ( isset( $settings[ $num ][\'title\'] ) ) {
return $settings[ $num ][\'title\'];
}
return $instance->name;
}