-
-
- Submit Updated Articles to Bing and Yandex with IndexNow in Joomla
- Add Published and Modified Date Meta Tags to Joomla
- Add Open Graph and Twitter Card Tags to Joomla
- Auto-Generate Meta Descriptions from Article Text in Joomla
- Add Noindex to Specific Pages in Joomla
- Verify Your Joomla Site with Google Search Console
-
- Add a View as Markdown Link to Joomla Articles
- Display the Last Modified Date in Joomla Articles
- Embed Iframes in Joomla
- Automatically Link Twitter (X) @mentions in Joomla Articles
- Open External Links in a New Tab in Joomla
- Display Estimated Reading Time in Joomla Articles
- Replace Old URLs in Joomla
- Search and Replace in Joomla
-
- Add a Footer Line to the Joomla Administrator
- Show a Staging Banner in the Joomla Administrator
- Remove the "All" Option from Admin List Limits in Joomla
- Add a Cookie Consent Banner to Joomla
- Make the Administrator Navigation Sticky in Joomla
- Add Google Fonts to Joomla
- Add a Facebook Messenger Chat Button to Joomla
- Add a Reading Progress Bar to Joomla
- Add a Custom Scrollbar to Joomla
- Show Confetti on a Thank You Page in Joomla
- Add Smooth Scrolling to Joomla
- Add a Back to Top Button in Joomla
- Add a WhatsApp Chat Button in Joomla
-
- Protect the Administrator with a Secret URL Key in Joomla
- Show a Welcome Message on First Login in Joomla
- Log Out Idle Administrators in Joomla
- Assign New Users to a Different User Group Automatically in Joomla
- Redirect Visitors by Country in Joomla
- Redirect Users After Login by User Group in Joomla
- Block User Registration with Certain Usernames in Joomla
- Block User Registration by Country in Joomla
- Block User Registration by Email Address in Joomla
- Block User Registration by IP Address in Joomla
- Remove the Forgot Password and Username Links in Joomla
- Remove the Generator Meta Tag in Joomla
- Let Users Log In with Their Email Address in Joomla
- Block Traffic by Country in Joomla
- Block Bot Traffic in Joomla
- Block Traffic by IP Address in Joomla
Reset Article Hits with a Webhook in Joomla
Set the hit counter of all Joomla articles, a category or one article to zero by opening a secret address from a browser or cron job, using one PHP snippet.
You tested the site for a month before launch and every article now claims hundreds of views that never happened. Or you'd like to start the counters fresh every January. Joomla has no button for that, and editing the hits in the database by hand gets old fast. You can reset article hits with a webhook in Joomla with one PHP snippet in Code Snippets.
The PHP snippet code
The snippet listens for a secret parameter on any frontend address. When the secret matches, it sets the hit counter of your articles to 0 and answers with a short JSON message, so a script or a scheduled task can check the result.
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;
// The secret your webhook URL must carry, as in /?resethits=your-secret.
// Use a long random string and keep it private.
$secret = 'change-me';
// Do not edit below.
$app = Factory::getApplication();
$input = $app->getInput();
$key = $input->getString('resethits', '');
// Do nothing until you set your own secret, or when the key is wrong.
if ($key === '' || $secret === 'change-me' || !hash_equals($secret, $key))
{
return;
}
$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->createQuery()
->update($db->quoteName('#__content'))
->set($db->quoteName('hits') . ' = 0');
// Optional: reset one article (&article=ID) or one category (&category=ID).
$article = $input->getInt('article', 0);
$category = $input->getInt('category', 0);
if ($article > 0)
{
$query->where($db->quoteName('id') . ' = :id')->bind(':id', $article, ParameterType::INTEGER);
}
elseif ($category > 0)
{
$query->where($db->quoteName('catid') . ' = :catid')->bind(':catid', $category, ParameterType::INTEGER);
}
$db->setQuery($query)->execute();
// Answer with JSON, so the caller can check the result.
$app->setHeader('Content-Type', 'application/json; charset=utf-8', true);
$app->sendHeaders();
echo json_encode(['reset' => $db->getAffectedRows()]);
$app->close();
Replace change-me in $secret with a long random string. The snippet does nothing while the sample value is still there, so no one can reset your counters before you've picked a secret of your own.
The webhook address is your site plus the secret:
https://example.com/?resethits=YOUR-SECRETresets every article.https://example.com/?resethits=YOUR-SECRET&category=12resets the articles in category 12.https://example.com/?resethits=YOUR-SECRET&article=34resets article 34 only.
The answer is {"reset":34}, where the number is how many articles had a counter above 0.
How to add this snippet
- Install Code Snippets if it isn't installed already.
- Log into your Joomla backend.
- Go to Components → Tassos Code Snippets.
- Click New.
- Enter a title, for example Reset hits webhook.
- Set Code Type to PHP.
- Set Insertion Method to Auto-Insert Locations.
- Set Location to On Page Load.
- Paste the code above into the editor.
- Replace
change-mewith your own secret. - Click Save & Close.
Check that it works
- Note the hits of an article under Content → Articles.
- Open
https://example.com/?resethits=YOUR-SECRET&article=IDin your browser, with your own site, secret and the article's ID.
The browser shows {"reset":1}, and the article's hits read 0 back in the list. With a wrong secret, the address shows your home page as usual and nothing changes.
To reset counters on a schedule, call the address from a cron job with curl, or from Joomla's own System → Scheduled Tasks with a task of the type GET Request.
The Clear the Cache with a Link in Joomla tutorial uses the same secret-link approach for the cache. To learn more about how PHP snippets work, read the PHP snippet docs.