PHP

Add custom attribute in Joomla 3.x addScript

W
W3Tweaks Team
Frontend Tutorials
Oct 30, 2017 1 min read
Add custom attribute in Joomla 3.x addScript
This tutorial will explain you, how add custom attributes in Joomla 3.x addScript()

This tutorial will explain you, how add custom attributes in Joomla 3.x addScript()

Find the code below

$doc = JFactory::getDocument(); 
$doc->addScript(JURI::root(true) . '/libraries/gantry/libs/google-code-prettify/prettify.js', array(), array('data-cfasync' => 'false'));

Find the detailed explanation about the above code.

Before calling addScript() have to call JFactory::getDocument() like below.

$doc = JFactory::getDocument();

$doc->addScript(url, version, attributes); addScript has three parameters 1st url, 2nd Version and 3rd attributes.

Find the demo image below

Demo Image: joomla add custom attributes in addscript