Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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>';
} );
 
PREVIOUS NEXT
Tagged: #Add #custom #column #custom #posts #list
ADD COMMENT
Topic
Name
3+4 =