WordPress: Disable Comments on Old Posts Automatically
Stop spam on old WordPress posts by closing comments automatically after a set number of days.
Add a thin reading-progress bar to the top of WordPress posts with a few lines of code — no plugin needed.
24 lines · Updated Nov 26, 2026
<!-- Add to your theme, e.g. in single.php before the content -->
<div id="reading-progress"></div>
<style>
#reading-progress {
position: fixed;
top: 0; left: 0;
height: 4px;
width: 0;
background: #8b5cf6;
z-index: 9999;
}
</style>
<script>
window.addEventListener('scroll', function () {
var article = document.querySelector('.entry-content');
if (!article) return;
var top = article.getBoundingClientRect().top;
var height = article.offsetHeight - window.innerHeight;
var progress = Math.min(100, Math.max(0, -top / height * 100));
document.getElementById('reading-progress').style.width = progress + '%';
});
</script>
A thin bar at the top of the page that fills up as the reader scrolls is a small touch that makes long articles feel shorter and more manageable. Most plugins that add it also load extra CSS and JavaScript on every page. This snippet adds a lightweight reading-progress bar to single posts with a few lines of vanilla JavaScript and CSS — no plugin and no jQuery.
requestAnimationFrame or a passive scroll listener keeps it smooth and cheap.is_singular('post') is true.top value so it sits just below the header.z-index.Does it affect performance? Barely — it is a few lines of code that only run while scrolling and do not trigger layout-heavy work.
Related: Dark mode toggle · 5 code snippets every developer needs
Paste the HTML, CSS and JavaScript into your theme's single-post template (for example single.php), or into a code-snippets plugin as a frontend snippet. Change .entry-content to your theme's content class if needed, and the colour to match your site.
Share this snippet
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.
Log every 404 on your WordPress site so you can see which broken links visitors actually hit — and fix them.