How to add a quicklink to the Posts Admin Published|Scheduled|Trash menu

You can use the views_{screen_id} filter (used here), which filters an array where the keys act as an ID for that ‘view’ and the value is the HTML to be used to display the view (such as ‘All’, ‘Draft’, ‘Trash’ etc.).

You can simply add extra links to this array:

add_filter( 'views_edit-post', 'wpse_add_my_view');
function wpse_add_my_view($views){
    global $post_type_object;
    $post_type = $post_type_object->name;

    $y =mysql2date('Y', current_time('mysql') );
    $m =mysql2date('m', current_time('mysql') );
    $d =mysql2date('d', current_time('mysql') );
    $views['today'] = "<a href="https://wordpress.stackexchange.com/questions/19418/edit.php?year=$y&monthnum=$m&day=$d&post_type=$post_type">".__('Today','myplugin')."</a>";

    return $views;
}

Of course – WordPress won’t automatically highlight your custom link (why would it?) – but to do that you you simply have to add the class current to the link when appropriate (check if the year, month and day are being queried?).

By default WordPress adds this class to ‘all’ – so when you add the class you’ll also need to remove it from ‘all’ (otherwise they will both appear bold). To do that, you can either replace the ‘all’ value or preg_replace to remove the class.

Leave a Comment