Dynamically Rename Column in the Post Admin Screen

190 Views Asked by At

I am working dynamically renaming a column in the post admin screen. The code that I have so far is through the manage_post_columns hook:

function rename_columns ( $columns ){
  $columns ['author'] = 'Writer';
  return $columns;
}

add_filter ('manage_posts_columns', 'rename_columns', 30 );

So far, it is hard-coded with 'Writer' but I would like to make that to make that field dynamic. I have built a settings page on the backend to enter the code and the data is being stored in the database but I seem to be stuck on how to pull that data dynamically. I have tried so far:

function rename_columns ( $columns ){
  $options = get_option( 'renamer_settings' );
  $columns ['author'] = esc_html( $options['custom-text'] );
  return $columns;
}
add_filter ('manage_posts_columns', 'rename_columns', 30 );

I would be grateful for any pointers! Any ideas how to dynamically pull the data into that field?

0

There are 0 best solutions below