johnode
johnode

Reputation: 740

Joomla 1.7: change meta tags from system plugin

Joomla version 1.7 Plugin enabled in admin part

Plugin code:

<?php
// no direct access
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

class plgSystemMetatags extends JPlugin
{   
    public function __construct(&$subject, $config)
    {
        parent::__construct($subject, $config); 
    }

    public function onBeforeRender()
    {
        $document =& JFactory::getDocument();
        $document->setMetaData('keywords', 'test keywords');    
    }   
}

But this doesn't work

Meta description renders value, which set in global configuration

plugin xml file

<?xml version="1.0" encoding="utf-8"?>
<extension version="1.7" type="plugin" group="system" method="upgrade" client="site">
    <name>System - Metatags</name>
    <author>Joomla! Project</author>
    <creationDate>November 2005</creationDate>
    <copyright>Copyright (C) 2005 - 2011 Open Source Matters. All rights reserved.</copyright>
    <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
    <authorEmail>[email protected]</authorEmail>
    <authorUrl>www.joomla.org</authorUrl>
    <version>1.7.0</version>
    <description></description>

    <files>
        <filename plugin="metatags">metatags.php</filename>
        <filename>index.html</filename>
    </files>

</extension>

Upvotes: 0

Views: 823

Answers (1)

Gaurav
Gaurav

Reputation: 28755

use onBeforeRender instead of onAfterRender.

When onAfterRender event is triggered the output of the application is already available in the response buffer.

Upvotes: 2

Related Questions