我想使用ACF(和CPT)允许用户从设置页面为管理仪表板小部件指定自定义名称。在下面的代码中,将创建一个小部件,名为;我的标题;。如果设置页面上的acf字段是“my\\u widget\\u name”,如何将其添加到代码中,以便显示在用户后端仪表板中?CPT应为;dashboard\\u提要;如果这很重要的话。
add_action( \'wp_dashboard_setup\', \'feed_dashboard_add_widgets\' );
function feed_dashboard_add_widgets() {
wp_add_dashboard_widget( \'dw_dashboard_widget_feed\', ( \'my title\' ), \'my_cool_widget\');
}
SO网友:Sébastien Serre
add_action( \'wp_dashboard_setup\', \'feed_dashboard_add_widgets\' );
function feed_dashboard_add_widgets() {
$title = __( \'My title\', \'textdomain\' ); //by default title
// if ACF is activated (prevent fatal) end your field not empty, define a new $title
if ( function_exists( \'get_field\' ) && ! empty( get_field(\'my_widget_name\' ) ){
$title = get_field(\'my_widget_name\' );
}
wp_add_dashboard_widget( \'dw_dashboard_widget_feed\', $title, \'my_cool_widget\');
}