WordPress: Disable Comments on Old Posts Automatically
Stop spam on old WordPress posts by closing comments automatically after a set number of days.
Add your own widget to the WordPress dashboard — show today's orders, a checklist, or quick links for your team.
21 lines · Updated Nov 26, 2026
<?php
// Add to your theme's functions.php or a code-snippets plugin.
add_action('wp_dashboard_setup', 'my_custom_dashboard_widget');
function my_custom_dashboard_widget() {
wp_add_dashboard_widget(
'my_site_widget', // widget id
'My Site — Quick Links', // title
'my_site_widget_content' // callback
);
}
function my_site_widget_content() {
echo '<ul>';
echo '<li><a href="' . admin_url('post-new.php') . '">Write a new post</a></li>';
echo '<li><a href="' . admin_url('edit.php') . '">All posts</a></li>';
echo '<li><a href="' . admin_url('upload.php') . '">Media library</a></li>';
echo '</ul>';
echo '<p>Today: ' . date_i18n(get_option('date_format')) . '</p>';
}
The WordPress dashboard is the first screen clients see after logging in, and it is usually full of widgets they never use. A custom dashboard widget lets you put something useful there instead: support contact details, quick links, a short guide, or key numbers like today's orders. This snippet registers your own widget with the WordPress Dashboard Widgets API.
wp_dashboard_setup, the action WordPress runs when building the dashboard.esc_html() and esc_url().current_user_can('manage_options').You can also remove default widgets you do not need with remove_meta_box() on the same hook, leaving a clean, branded dashboard.
Related: Custom login page logo · Log 404 errors
Add the code to your theme's functions.php or a code-snippets plugin. Change the title, links and content to show what your team needs — for example today's order count from WooCommerce.
Share this snippet
Stop spam on old WordPress posts by closing comments automatically after a set number of days.
Log every 404 on your WordPress site so you can see which broken links visitors actually hit — and fix them.
Brand the WordPress login page with your own logo and link — a few lines of code, no plugin needed.