I'm trying to remove unwanted scripts from my custom joomla template header, which I've managed to remove everything except for this:
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery('.hasTooltip').tooltip({});
});
</script>
I've searched for hours and I've tried numerous things to get it removed, but I can't seem to get rid of it. Here's what I've done to remove the other scripts I don't want (for anyone else who has this issue):
# unset frameworks
JHtml::_('bootstrap.framework',false);
JHtml::_('jquery.framework',false);
# unset scripts
unset($doc->_scripts[$this->baseurl.'/media/jui/js/jquery.min.js']);
unset($doc->_scripts[$this->baseurl.'/media/jui/js/jquery-noconflict.js']);
unset($doc->_scripts[$this->baseurl.'/media/jui/js/bootstrap.min.js']);
If someone could help me remove that tooltip javascript, that would be fantastic. Oh and I don't want to touch the core files, so I'm trying to remove it from the template index.php file itself.
Based on Joomla documents, 2 things to consider:
a) In the below code, you're actually enabling/including bootstrap and jquery:
When bootstrap is enabled, joomla automatically enables jquery, and if joomla enabled jquery, joomla automatically enables tooltip.
Just don't call these functions. The
unset
you used will remove bootstrap and jquery correctly:b) if the tooltip script is still included, it's probably inserted by
JHtml::_('behavior.tooltip');
somewhere in the used component.Lastly, never never never modify Joomla core files. it's a worst-practice.
PS. For those who mentioned that the tooltip script is inserted but they don't find it in the
$doc
, that's because the$doc
doesn't contain inline scripts.I have already meet this issue, I am using Joomla 3. If it is your case then you can solve it by doing this : Joomla 3 comes with jQuery on board, so by adding Joomla yourself, this may generate the issue. Also make sure you include your jQuery over
<jdoc:include type="head" />
. If you necessary wants to include it. But I do not recommend this. Hope this helpsI had the same problem when I was building a Joomla template/site with only HTML5, CSS3 and some small jQuery plugins for effects. It was unworthy of including heavy Bootstrap just to show some tooltips which I also didn't use at all.
Althought I already unset media/jui/js/bootstrap.min.js from JDocument but these lines of code
were still appended by libraries/cms/html/bootstrap.php. So I got error "function tooltip not found".
I solved that by adding an empty function to my template's JS file.
You'll have to manually parse
$doc->_script
. The$doc->_scripts
array contains scripts that are linked to another source while$doc->_script
is for script declarations like the tooltip one.Create a system plugin with the follow code.
The First foreach loop
unset
s the.js
file(s) added to the head. And the next foreach loopunset
s thejs
code injected inside<script>
tags.There are two separate properties containing the scripts the
_script
&_scripts
I managed to get rid of the embedded javascript using this code in my template's index.php file:
disclaimer: I am not a PHP developer, so use above code at your own risk :)