The new Site Activity dashboard widget defaults to showing 5 comments. I'd like to show 10.

I can see the code in core /wp-admin/includes/dashboard.php where it calls the function wp_dashboard_site_activity, and uses wp_dashboard_recent_comments ( $total_items = 5 ). But I don't know the syntax to hook into this function to update it.

I know how to create a custom functionality plugin & edit functions.php, I'm just unsure of the syntax and/or hook to use.

Any help is greatly appreciated. Thanks.

up vote 8 down vote accepted

Seems like there is no filter for this (yet), but you can unregister the default activity widget and register (within your functions, or even better within your plugin as recommended by Dave Warfel) a similar activity widget with your custom settings:

// unregister the default activity widget
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
function remove_dashboard_widgets() {

    global $wp_meta_boxes;
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);

}

// register your custom activity widget
add_action('wp_dashboard_setup', 'add_custom_dashboard_activity' );
function add_custom_dashboard_activity() {
    wp_add_dashboard_widget('custom_dashboard_activity', 'Activity', 'custom_wp_dashboard_site_activity');
}

function custom_wp_dashboard_site_activity() {

    echo '<div id="activity-widget">';

    $future_posts = wp_dashboard_recent_posts( array(
        'display' => 2,
        'max'     => 5,
        'status'  => 'future',
        'order'   => 'ASC',
        'title'   => __( 'Publishing Soon' ),
        'id'      => 'future-posts',
    ) );

    $recent_posts = wp_dashboard_recent_posts( array(
        'display' => 2,
        'max'     => 5,
        'status'  => 'publish',
        'order'   => 'DESC',
        'title'   => __( 'Recently Published' ),
        'id'      => 'published-posts',
    ) );

    $recent_comments = wp_dashboard_recent_comments( 10 );

    if ( !$future_posts && !$recent_posts && !$recent_comments ) {
        echo '<div class="no-activity">';
        echo '<p class="smiley"></p>';
        echo '<p>' . __( 'No activity yet!' ) . '</p>';
        echo '</div>';
    }

    echo '</div>';

}
  • 1
    Tested & worked great. But I would recommend keeping this code in a custom functionality plugin, as it relates to the wp-admin, and is not theme-specific. – Dave Warfel Dec 20 '13 at 19:11
  • Good point! I added it to the answer :) – Sven Dec 20 '13 at 22:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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