How to disable front-end login in Joomla
The login feature on Joomla is default and you cannot disable it normally. If done wrong, it can cause errors and you won't be able to log into the admin area - which is terrible.
However, for security reasons, not all websites want to integrate this login feature. They want to turn it off to restrict the risks.
There are some simple ways like turning off the login module or editing the file (deleting the controller.php file)... however, these are not optimal. Why?
- If the module is disabled, users can still login to your website using the link https://example.com/index.php?option=com_users&view=login
- If you edit the core file, you cannot update Joomla to the new version.
In this article, I will show you how to disable the login feature and still meet the above requirements.
This article uses PHP language, so you need a module that supports it. You can use the module Flexi Custom Code (I will use it in this article), download it here. Let's get started!
----------------------
First, download and install the Flexi Custom Code module.
Next, go to the Admin section > Manage modules > New > Flexi Custom Code.
At the module's settings page, set the value for USING PHP CODE? is Yes.
In the Insert Code field, enter:
-- With J2.5 and J3:
<?php
$app = JFactory::getApplication();
$option = $app->input->getCmd('option');
if($option=='com_users')
{
// J2.5
// JError::raiseError(404, 'Page Not Found');
// J3
throw new Exception('Page Not Found.', 404);
}
-- With J4:
<?php
use Joomla\CMS\Factory;
$app = Factory::getApplication();
$option = $app->input->getCmd('option');
if($option=='com_users')
throw new Exception('Page Not Found.', 404);
Then you choose where to display the module to display it on the entire site (Module Assignment: On all pages).
Done! This feature will no longer be available on your site.
Here is the working page on the test site:
https://testsite.formalms.org/forma-plugins/375-2factor-authentication-plugin.html
Here the production site:
https://formalms.org/forma-plugins/375-2factor-authentication-plugin.html