ASSET-ADDSCRIPT-DECLARATION-001
$doc->addScriptDeclaration()
addScriptDeclaration / addStyleDeclaration
Declarations still work on Document but they skip asset ordering. WAM inline APIs are the Joomla 4+ path.
$doc->addScriptDeclaration() → WebAssetManager addInlineScript / addInlineStyle
Symptoms people search
inline js before jquery · addScriptDeclaration
Replace this code
Swap $doc->addScriptDeclaration() for WebAssetManager addInlineScript / addInlineStyle.
Joomla 3
Remove or stop calling this
$doc->addScriptDeclaration('alert(1);');
$doc->addStyleDeclaration('h1{color:red}');Joomla 4 / 6
Use this instead
$wa->addInlineScript('alert(1);');
$wa->addInlineStyle('h1{color:red}');How to fix it
- 1Move inline JS/CSS to WAM.
- 2Prefer a file in joomla.asset.json for anything reused.
Also known as
addScriptDeclaration · addStyleDeclaration · addInlineScript
Related issues
- Joomla 3 → 4JavaScript
behavior.framework (MooTools)
JHtml::_('behavior.framework') → Do not load MooTools — use vanilla JS or WebAssetManager
- Joomla 3 → 4JavaScript
JHtmlBootstrap::modal()
JHtmlBootstrap::modal() → HTMLHelper::_('bootstrap.renderModal')
- Joomla 3 → 4JavaScript
Chosen.js (formbehavior.chosen)
JHtml::_('formbehavior.chosen') → Core styled <select>, Choices.js, or Tom Select
- Joomla 4 → 5JavaScript
addScript() / addStyleSheet() vs WebAssetManager
$doc->addScript() → WebAssetManager + joomla.asset.json
- Joomla 5 → 6JavaScript
Assuming jQuery is always on the page
JHtml::_('jquery.framework') → Declare jQuery in joomla.asset.json only if you still need it
- Joomla 5 → 6JavaScript
Joomla.JText (JavaScript)
Joomla.JText._() → Joomla.Text._() + Text::script() in PHP