Answers for "Add custom column at custom posts list"

PHP
0

Add custom column at custom posts list

<?php
manage_{$post->post_type}_posts_custom_column
manage_{$post->post_type}_posts_columns
  
Here's an example how we could display a button, for each row in the send_email column:

/**
 * Books Post Table: Display a utton in each row in the 'send_email' column
 */
add_action( 'manage_books_posts_custom_column', function ( $column_name, $post_id ) 
{
    if ( $column_name == 'send_email')
        printf( '<input type="button" value="%s" />', esc_attr( __( 'Send Email' ) ) );

}, 10, 2 );

To add the send_email column we can use:

/**
 * Books Post Table: Add the 'send_email' column
 */
add_filter('manage_books_posts_columns', function ( $columns ) 
{
    if( is_array( $columns ) && ! isset( $columns['send_email'] ) )
        $columns['send_email'] = __( 'Send Email' );     
    return $columns;
} );
We could also limit the column width with:

/**
 * Limit the 'send_email' column width
 */
add_action( 'admin_print_styles-edit.php', function()
{        
    echo '<style> .column-send_email { width: 100px; }</style>';
} );
Posted by: Guest on May-07-2022

Code answers related to "Add custom column at custom posts list"

Browse Popular Code Answers by Language