Inside the recaptcha.php file of the Recaptcha Plugin on Joomla 3.6, I have the following code:

case '2.0':
            $theme = $this->params->get('theme2', 'light');
            $file  = 'https://www.google.com/recaptcha/api.js?hl=' . JFactory::getLanguage()->getTag() . '&render=explicit';

            JHtml::_('script', $file, true, true);

            $document->addScriptDeclaration('jQuery(document).ready(function($) {$(window).load(function() {'
                . 'grecaptcha.render("' . $id . '", {sitekey: "' . $pubkey . '", theme: "' . $theme . '"});'
                . '});});'

Which creates the string:

<script src="https://www.google.com/recaptcha/api.js?hl=en-US&amp;render=explicit" type="text/javascript"></script>

loading the api.js for the recaptcha. Since I am using Rocket Loader from Cloudflare I would like to change this

<script src="https://www.google.com/recaptcha/api.js?hl=en-US&amp;render=explicit" type="text/javascript"></script>

to this

<script data-cfasync="false" src="https://www.google.com/recaptcha/api.js?hl=en-US&amp;render=explicit" type="text/javascript"></script>

where after the

I tried using a variable $cloud = 'data-cfasync="false"'; and changing JHtml::('script', $file, true, true); to JHtml::('script', $cloud, $file, true, true); or I tried JHtml::script data-cfasync="false" ($file, true, true); or JHtml::('script data-cfasync="false"', $file, true, true); or JHtml::('script'.'data-cfasync="false"', $file, true, true); And nothing worked....... I know some of them are stupid but I am not a real programmer as you have figured out already. How can I do that? Thanks

2 Answers 2


As of Joomla 3.7, the arguments for JHtml were updated whilst keeping backward compatibility.

So rather than passing , true, true, you need to pass an array of options, then an array of attributes, like so:

JHtml::_('script', $file, array('version' => 'auto'), array('data-cfasync' => false));

You can have a look at the source code here: https://github.com/joomla/joomla-cms/blob/staging/libraries/src/HTML/HTMLHelper.php#L679

Hope this helps


OK the answer came from here https://stackoverflow.com/questions/52953066/i-would-like-to-add-a-string-after-script-at-jhtml-script-file-true-t where I posted the same question. In Joomla version 3.4.8 that I have on the website the way to put a string inside the tags is:

$script = '<script src="' . $file . '" data-cfasync="false"></script>';
$document = JFactory::getDocument();

I thank you very much I appreciate your help Best Regards George

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.