最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

admin - Allow users to give a dashboard widget a custom name using ACF

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

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
Add a comment  | 

1 Answer 1

Reset to default 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');
 }
发布评论

评论列表(0)

  1. 暂无评论