I want to use ACF (and CPT) to allow users to give a custom name to an admin dashboard widget from a settings page. In the below code, a widget would be created called "my title". If the acf field on the settings page is 'my_widget_name' - how do I add it to my code so it shows up in the users backend dashboard? CPT would be "dashboard_feeds" if that is important.
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');
}
I want to use ACF (and CPT) to allow users to give a custom name to an admin dashboard widget from a settings page. In the below code, a widget would be created called "my title". If the acf field on the settings page is 'my_widget_name' - how do I add it to my code so it shows up in the users backend dashboard? CPT would be "dashboard_feeds" if that is important.
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');
}
Share
Improve this question
asked Jan 30, 2022 at 19:26
Doug HigsonDoug Higson
386 bronze badges
1 Answer
Reset to default 0add_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');
}