1

I'm using this lines to remove header scripts of Joomla I don't need it :

$doc = JFactory::getDocument();

$dontInclude = array(
    '/media/jui/js/bootstrap.min.js'
);

foreach($doc->_scripts as $key => $script){
    if(in_array($key, $dontInclude)){
        unset($doc->_scripts[$key]);
    }
} 

Everything works fine in all pages except those who point to a custom component. There is no override of head in my component and cache is disabled.

I'm using Joomla 3.3.3

Edit: If I print the document object from my component, scripts is an empty array...

Thanks in advance

  • You do realise that unsetting this file will result in a console log error and loss of functionality such as editing an article in the frontend – Lodder Aug 21 '14 at 10:07
  • Could you use a plugin such as JQuery easy to exclude the script from specific pages? Plugin details here simplifyyourweb.com/index.php/developers-corner/… – jonboy Aug 21 '14 at 10:12
  • @Lodder I know, I just want to replace the current version of Bootstrap. – Dayron Gallardo Aug 21 '14 at 14:36
  • Where are you putting this code? In a component, a plugin, your template? – David Fritsch Aug 21 '14 at 16:53
  • Be sure to use the underscore. It's _scripts and not scripts. – Farahmand Aug 21 '14 at 21:43
2

You should probably be doing this in a system plugin using the onBeforeRender event. At this point in execution, the page is about to be rendered, so the scripts should be in place.

Something like this:

function onBeforeRender() {
  $doc = JFactory::getDocument();

  $dontInclude = array(
    '/media/jui/js/bootstrap.min.js'
  );

  foreach($doc->_scripts as $key => $script){
    if(in_array($key, $dontInclude)){
        unset($doc->_scripts[$key]);
    }
  } 
}

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.