WordPress与ACF管理:后台自定义列添加位置列需求
Got it, let's solve this! You've already extended the ACF field group list with an "Order" column using acf_field_group_columns, and now you want to add a Position column that clearly shows where each field group appears on the post edit screen—like "After Title", "Normal" (main content area), or "Sidebar".
Here's the complete, step-by-step implementation:
1. Extend the Columns Array
First, update your existing acf_field_group_columns function to add the new "Position" column to the columns list:
function acf_field_group_columns($columns) { // Keep your existing "Order" column $columns['menu_order'] = __('Order'); // Add the new "Position" column $columns['position'] = __('Position'); return $columns; } add_filter('acf/field_group/admin_columns', 'acf_field_group_columns');
2. Populate the Position Column Content
Next, use ACF's acf/field_group/admin_column_content hook to fill the column with human-readable position labels. ACF stores field group positions as raw values (acf_after_title, normal, side), so we'll map those to friendly names:
function my_acf_field_group_position_column($content, $field_group) { // Map ACF's raw position values to user-friendly labels switch ($field_group['position']) { case 'acf_after_title': return __('After Title'); case 'normal': return __('Normal (Main Content Area)'); case 'side': return __('Sidebar'); default: return __('Unknown Position'); } } add_action('acf/field_group/admin_column_content/name=position', 'my_acf_field_group_position_column', 10, 2);
How This Works
- The
acf/field_group/admin_columnsfilter lets you modify the columns shown on the ACF field groups list page. - The
acf/field_group/admin_column_content/name=positionaction targets the specific "position" column we added, and passes the$field_groupobject so we can access its position data. - We use a switch statement to convert ACF's internal position values into labels that make sense for site managers.
Just drop both functions into your theme's functions.php file, or a custom plugin, and you'll see the new Position column in your ACF field group list immediately!
内容的提问来源于stack exchange,提问作者morgyface

