Initial problem:
I am using a particular Joomla plugin which is very good in many ways. However, it adds a bunch of Javascript to my <head>
element which I do not desire. (I am by no means philosophically against the plugin using Javascript. It's just that the Javascript output by the plugin is bad. Perhaps not bad in the general case, but it breaks what I'm trying to do with my site. Anyway, I'm going off on a tangent. I'll rein it in...)
So my solution is that I want to control what <jdoc:include type="head" />
includes in my page. I want to strip out that bad piece of Javascript. But how?
My first attempt:
Being fairly knowledgeable about PHP if not about Joomla, my initial thought was... "aha! output buffering!"
I added <?php ob_start(); ?>
to my template before <jdoc:include type="head" />
and did a little ob_get_contents()
stuff afterwards. But of course, this just literally captures the string '<jdoc:include type="head" />'
. It is only later; after the template has finished running that the jdoc includes are processed. Silly me.
So how do I cut this crud out?
Given you're "knowledgeable about PHP" I would suggest not using a hack like this as it's likely to break in a future update of Joomla.
All plugins are php
, you could edit that rather than creating an override that replaces a fairly core file.
It's also pretty easy to create a plugin that traps various system triggers/events, if you didn't want to edit the original plugin. Joomla Doc's has a whole category on Plugin Development.
I would imagine a System
plugin that handles on the render or head events would be the place to trap it at, i.e. onAfterRender
, onBeforeRender
or onBeforeCompileHead
Alternatively you could try a plugin like this one "Skyline Script Remover" from the Joomla Extension directory, found in this search.