Technical Library / Open Source

Joomla Snippets

Searchable collection of production-ready code recipes for template overrides, modules, plugins, and Joomla! 3 to 6 APIs.

100 Snippets
12 Categories
J3 to J6 Compatibility
Showing 9 of 9 snippets
PHP J6 J5 J3 Template Override
Content Plugins and Languages

Process Content Plugins (content.prepare) on Custom Text

Evaluates shortcodes such as {loadposition}, {loadmodule} and content plugins on arbitrary text from custom components or database queries.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;

// Aplica todos os plugins do grupo "content" ao texto informado
// ...
50 201 2 versions
PHP J6 J5 J3 Template
Content Plugins and Languages

Detect the Active Site Language Tag

Returns the active BCP-47 language tag (such as pt-BR or en-GB) using $app->getLanguage()->getTag().

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$langTag = Factory::getApplication()->getLanguage()->getTag();
// ...
48 189 2 versions
PHP J6 J5 J3 Plugin
Content Plugins and Languages

Trigger onContentPrepare via Helpers\Content::prepare()

Replaces removed Joomla 3 JHtmlContent::prepare() with Joomla\CMS\HTML\Helpers\Content::prepare() in Joomla 5 and 6.

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\Helpers\Content;

echo Content::prepare((string) $text);
33 140 2 versions
PHP J6 J5 Plugin
Content Plugins and Languages

Build a Native Joomla 5 and 6 Plugin with ServiceProvider and SubscriberInterface

Wires a modern plugin via DI container with SubscriberInterface and explicit typed event subscriptions.

<?php

declare(strict_types=1);

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
// ...
59 203
PHP J6 J5 J3 Helper / API
Content Plugins and Languages

Load a Language (.ini) File Manually and Translate with Text::_()

Loads .ini translation constants from another component, module or template so Text::_() and Text::sprintf() resolve cleanly.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;

// ...
40 144 2 versions
PHP J6 J5 J3 Helper / API
Content Plugins and Languages

Query Multilingual Item Associations with Associations::getAssociations()

Retrieves linked translations of an article or custom item to generate hreflang links or direct language switch buttons.

<?php

declare(strict_types=1);

use Joomla\CMS\Language\Associations;

$associated = Associations::getAssociations(
// ...
33 125 2 versions
PHP J6 J5 J3 Template
Content Plugins and Languages

List All Published Content Languages with LanguageHelper

Returns active content languages (lang_code, sef, title_native) to build custom switchers or hreflang markup.

<?php

declare(strict_types=1);

use Joomla\CMS\Language\LanguageHelper;

$languages = LanguageHelper::getContentLanguages([1], true, null, 'ordering', 'asc');
// ...
24 100 2 versions
PHP J6 J5 J3 Plugin
Content Plugins and Languages

Dispatch a Custom Plugin Event with the Event Dispatcher

Imports a plugin group and dispatches an extensible event object via $app->getDispatcher()->dispatch() in Joomla 5 and 6.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Event\Event;
// ...
38 140 2 versions
PHP J6 J5 J3 Plugin
Content Plugins and Languages

Parse Custom Shortcodes Inside onContentPrepare

Replaces {mywidget id=12} tokens inside articles using typed ContentPrepareEvent and a fast str_contains guard.

<?php

declare(strict_types=1);

use Joomla\CMS\Event\Content\ContentPrepareEvent;

public function onContentPrepare(ContentPrepareEvent $event): void
// ...
44 161 2 versions
Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.