0

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');
 }

1 Answer 1

0
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');
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.