I am trying to create a plugin that will add the following in the of pages:
<meta http-equiv="origin-trial" content="MY_CHROME_TRIAL_TOKEN">
I assume this should be a system plugin that targets the onAfterRender event so have added this code (I have substituted the real token):
public function onAfterRender()
{
$document = JFactory::getDocument();
$document->setMetaData('origin-trial', 'mychrometrialtoken');
}
The plugin installs but the meta tag is not added to the page header. What am I doing incorrectly? I am a novice at this so have used a plugin template from Github and modified it. I have probably made a basic error! I wonder if I have specified the tagname 'origin-trial' incorrectly.
XML file:
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="system">
<name>plg_system_tdcchromexhrenable</name>
<author>AG</author>
<creationDate>8 September 2020</creationDate>
<copyright>Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.0</version>
<description>Enable the XHR synchronous setting in Chrome to prevent SCORM errors</description>
<files>
<filename plugin="tdcxhr">tdcxhr.php</filename>
<filename>index.html</filename>
</files>
</extension>
PHP:
<?php
// no direct access
defined( '_JEXEC' ) or die;
class plg<system><plg_system_tdcchromexhrenable> extends JPlugin
{
/**
* Load the language file on instantiation. Note this is only available in Joomla 3.1 and higher.
* If you want to support 3.0 series you must override the constructor
*
* @var boolean
* @since 3.1
*/
protected $autoloadLanguage = true;
/**
* Plugin method with the same name as the event will be called automatically.
*/
function onBeforeCompileHead()
{
$document = JFactory::getDocument();
$document->setMetaData('origin-trial', 'token_goes_here','http-equiv');
return true;
}
}
?>
onBeforeCompileHead
, which will add your meta tag to the<head>
before it's rendered...which is what you need so that it's there before page load. And +1 for using a plugin – Lodder Sep 7 '20 at 9:21die;
inside your function. If you see a blank page, then the plugin is actually working – Lodder Sep 8 '20 at 10:38