To create a Joomla plugin that includes the Font Awesome CDN in the head section of a Joomla website, independent of the template, you can follow these steps:

Joomla 3.x

  1. Create the plugin folder:

    • Create a new folder in the plugins directory of your Joomla installation. You can name it something like plg_fontawesome.
  2. Create the plugin manifest file:

    • Inside the plg_fontawesome folder, create a new file called plg_fontawesome.xml.
    • Open plg_fontawesome.xml in a text editor and add the following code:

<?xml version="1.0" encoding="utf-8"?>

<extension version="3.9" type="plugin" group="system" method="upgrade">

    <name>Font Awesome CDN Plugin</name>

    <author>WebsiteFunctions.com</author>

    <version>1.0</version>

    <description>Adds Font Awesome CDN to the head section of the website.</description>

    <files>

        <filename plugin="fontawesome">fontawesome.php</filename>

    </files>

</extension>

    3. Create the plugin PHP file:

  • In the plg_fontawesome folder, create a new file called fontawesome.php.
  • Open fontawesome.php in a text editor and add the following code:

<?php

defined('_JEXEC') or die;

 

use Joomla\CMS\Plugin\CMSPlugin;

 

class PlgSystemFontawesome extends CMSPlugin

{

    public function onAfterDispatch()

    {

        $document = JFactory::getDocument();

        $document->addScript('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js');

    }

}

 

 

Install the plugin:

    • Create a ZIP archive of the plg_fontawesome folder.
    • Log in to your Joomla administration panel.
    • Go to "Extensions" -> "Manage" -> "Install".
    • Choose the ZIP archive you created and click "Upload & Install".

       

    •  
    • Enable the plugin:

      • After installing, go to "Extensions" -> "Plugins".
      • Search for "Font Awesome CDN Plugin" and click on it.
      • Set the "Status" to "Enabled" and click "Save & Close".

The plugin is now installed and active on your Joomla website. It will include the Font Awesome CDN in the head section of every page. Make sure to update the Font Awesome CDN URL in the fontawesome.php file if a newer version becomes available.

Note: This example assumes you are using Joomla 3.x. If you are using a different version, the structure and code might vary slightly.

 

Joomla 4.x

Joomla 4 has introduced significant changes, including a new plugin structure and namespaces.

To make the Font Awesome CDN plugin compatible with Joomla 4, you'll need to update the code and follow the new plugin structure. Here's an updated version of the plugin code for Joomla 4:

Create the plugin folder:

    • Create a new folder in the plugins directory of your Joomla 4 installation. Name it something like fontawesome.

Create the plugin manifest file:

  • Inside the fontawesome folder, create a new file called fontawesome.xml.
  • Open fontawesome.xml in a text editor and add the following code:

 

 

<?xml version="1.0" encoding="utf-8"?>

<extension version="4.0" type="plugin" group="system" client="site">

    <name>Font Awesome CDN Plugin</name>

    <author>WebsiteFunctions.com</author>

    <version>1.0</version>

    <description>Adds Font Awesome CDN to the head section of the website.</description>

    <files>

        <filename plugin="fontawesome">fontawesome.php</filename>

    </files>

</extension>

 

 

Create the plugin PHP file:

  • In the fontawesome folder, create a new file called fontawesome.php.
  • Open fontawesome.php in a text editor and add the following code:

<?php

namespace Joomla\Plugin\System\Fontawesome;

 

use Joomla\CMS\Plugin\CMSPlugin;

 

defined('_JEXEC') or die;

 

class FontawesomePlugin extends CMSPlugin

{

    public function onAfterDispatch()

    {

        $document = $this->container->get('document');

        $document->addScript('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js');

    }

}

 

 

Install and enable the plugin:

    • Create a ZIP archive of the fontawesome folder.
    • Log in to your Joomla administration panel.
    • Go to "Extensions" -> "Install".
    • Choose the ZIP archive you created and click "Upload & Install".
    • After installing, go to "Extensions" -> "Plugins".
    • Search for "Font Awesome CDN Plugin" and click on it.
    • Set the "Enabled" field to "Yes" and click "Save & Close".

The plugin is now installed and active on your Joomla 4 website. It will include the Font Awesome CDN in the head section of every page.

Please note that this code is compatible with Joomla 4, but additional modifications might be required depending on your specific needs or any changes in future versions of Joomla.

Also, if you need to use a different version of Font Awesome, just replace the CDN link in the the cose accordingly.