-
-
- 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
How to debug PHP errors in a snippet
Where to find the error when a PHP snippet fails in Joomla, what gets a snippet auto-disabled, the mistakes you'll meet most often, and how to fix each one.
When a PHP snippet fails, Code Snippets disables it and keeps the error for you. This article shows where to find it, what the common errors mean, and how to see the ones that don't disable the snippet.
Where the error shows up
- The snippets list. The failed snippet's status reads Auto-Disabled, and the Status filter has an entry for it.
- The edit screen. Open the snippet. The error message, the stack trace and the error date sit at the top.
- The Error Logs page. Click Error Logs in the toolbar of the snippets list. Each snippet gets its own log file under
administrator/logs/tassos_code_snippets/, and the page lets you read and clear them. - Your inbox. The site's administrator email address receives the error details.
The log file and the email are on by default. Turn them off in the component's Options, under Log Errors and Notify Admin.
What disables a snippet, and what doesn't
Any exception or error the snippet throws disables it. Since version 1.0.2 so does a fatal error PHP can't throw: a function or class declared twice, exhausted memory, or the execution time limit. The snippet goes to Auto-Disabled and the next request works.
Two cases leave the snippet published. A plain exit() or die() ends the request without an error. A loop that only waits (a sleep(), a slow HTTP call) never reaches PHP's time limit on Linux, so it hangs instead. For both, safe mode pauses every snippet so you can get in and fix it.
Common errors and their fixes
Call to undefined function, or class not found
A Joomla class is used without its namespace. Add a use line at the top of the snippet, for example use Joomla\CMS\Factory;, or write the full name: \Joomla\CMS\Factory::getApplication().
Cannot redeclare function
Two published snippets declare the same function, so the second one fails and gets disabled. Keep shared functions in one snippet, give the others a prefix, or guard the declaration:
if (!function_exists('my_helper'))
{
function my_helper()
{
// ...
}
}
Maximum execution time exceeded
A loop that never ends, or one that waits on a slow service on every request. Check the loop's exit condition, and keep slow HTTP calls behind a condition or a cache so they don't run on every page.
Seeing warnings and notices
Warnings, notices and deprecations don't disable the snippet and don't reach the log. To see them, set Error Reporting to Maximum under System → Global Configuration → Server, on a staging site. They then print on the page.
Debugging without a debugger
Queue a message to prove a line is reached, or to look at a value. It shows in Joomla's message area on the site and in the administrator:
use Joomla\CMS\Factory;
$app = Factory::getApplication();
$app->enqueueMessage('Reached line 12, user id ' . $app->getIdentity()->id, 'notice');
For values you want to keep, write them to a log file in administrator/logs:
use Joomla\CMS\Log\Log;
Log::addLogger(['text_file' => 'my-snippet.php'], Log::ALL, ['my-snippet']);
Log::add('Reached line 12', Log::INFO, 'my-snippet');
When several snippets interact, unpublish all but one and add them back one at a time.
Re-enable the snippet
Fix the code, set Status back to Published and save. Saving a published snippet clears the stored error and its date.
If the snippet runs but nothing happens, Why your PHP snippet isn't running has the checklist. The PHP snippet docs cover the events, the document type check and the blocked functions.