3

On edit.php, the main content is a list of posts, with columns including the published date.

I'd like to change the date format of the published date just on the admin page. In this case, I don't want to change what the users see; I want to change what the admin sees.

I want to add the day of the week to the published/scheduled date, because I'm planning to publish "Every Tuesday, at least," and want to make sure I've scheduled posts correctly.

After searching, the best route seems like it would be to create a custom field, but if there's a more subtle way to do this, I'd prefer to not install the custom field plugin.

edit: thanks to Bainternet's comment, I see that I already have custom fields (the option was just hidden by default). And, I see custom fields are not what I want. The data already exists; I just want to format it differently on the screen.

3
  • Custom fields are built-in the WordPress core so you don't have to install any plugin
    – Bainternet
    Commented Jun 4, 2011 at 12:58
  • ah; sorry, I hadn't read far enough to see "Custom Fields are hidden by default if they have not been used before." I'm still optimistic I can change the format and not actually add a new field. Commented Jun 4, 2011 at 13:50
  • for more info, have a read of this WP codex article: codex.wordpress.org/Formatting_Date_and_Time
    – Tara
    Commented Jun 4, 2011 at 18:29

2 Answers 2

9
  1. Add a column to the post edit screen and format the date however you like.

  2. Remove the default Date column.

EDIT here's the code to put inside your theme's functions.php file:

EDIT 2 added additional code to add publish status and make the column sortable, this should now be a complete copy of the original date column.

function my_custom_columns( $columns ) {
  unset( $columns['date'] );
  $columns['mydate'] = 'My Custom Date';
  return $columns;
}

function my_format_column( $column_name , $post_id ) {
    if($column_name == 'mydate'){
        echo get_the_time( 'l, F j, Y', $post_id )."<br>".get_post_status( $post_id );
    }
}

function my_column_register_sortable( $columns ) {
    $columns['mydate'] = 'mydate';
    return $columns;
}

function my_column_orderby( $vars ) {
    if ( isset( $vars['orderby'] ) && 'mydate' == $vars['orderby'] ) {
        $vars = array_merge( $vars, array(
            'orderby' => 'date'
        ) );
    }
    return $vars;
}

function my_column_init() {
  add_filter( 'manage_posts_columns' , 'my_custom_columns' );
  add_action( 'manage_posts_custom_column' , 'my_format_column' , 10 , 2 );
  add_filter( 'manage_edit-post_sortable_columns', 'my_column_register_sortable' );
  add_filter( 'request', 'my_column_orderby' );
}
add_action( 'admin_init' , 'my_column_init' );

Thanks to Scribu for his tutorial on sortable columns

5
  • I've been super busy at work and haven't taken time to try this, but it seems like it won't work. Step one above adds a new column with new data, right? Wouldn't I need to recreate the functionality of the default Date column? (so it shows up as the published date of the post) Commented Jun 8, 2011 at 16:27
  • @Thunder Rabbit - see update with code above.
    – Milo
    Commented Jun 8, 2011 at 17:06
  • @Thunder Rabbit - 2nd update, added more code.
    – Milo
    Commented Jun 8, 2011 at 17:46
  • Fantastic!! The only fault I can find is not telling me where it should go. Hmph! making me do research... ;-) (I've edited your answer above to add the key ingredient) Commented Jun 9, 2011 at 6:00
  • I just updated to 3.2 and don't have time to implement my old hack again, but I don't have to: Your code continues to work beautifully. Thank you. Thank you. Dear everyone! DON'T HACK CORE FILES!! Commented Jul 10, 2011 at 2:23
8

You can simply use the filter post_date_column_time:

add_filter( 'post_date_column_time' , 'my_post_date_column_time' , 10 , 2 );

function my_post_date_column_time( $h_time, $post ) {
    $h_time = get_post_time( 'l, F j, Y', false, $post );
    return $h_time;
}
2
  • 3
    And there's a similar filter for the status: post_date_column_status
    – Xander
    Commented Nov 22, 2018 at 10:28
  • Plain and simple. Thanks!
    – Eje
    Commented Nov 1, 2019 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.