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.

  • Custom fields are built-in the WordPress core so you don't have to install any plugin – Bainternet Jun 4 '11 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. – Thunder Rabbit Jun 4 '11 at 13:50
  • for more info, have a read of this WP codex article: codex.wordpress.org/Formatting_Date_and_Time – Tara Jun 4 '11 at 18:29
6
  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

| improve this answer | |
  • 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) – Thunder Rabbit Jun 8 '11 at 16:27
  • @Thunder Rabbit - see update with code above. – Milo Jun 8 '11 at 17:06
  • @Thunder Rabbit - 2nd update, added more code. – Milo Jun 8 '11 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) – Thunder Rabbit Jun 9 '11 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!! – Thunder Rabbit Jul 10 '11 at 2:23
5

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;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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