Store
Community Documentation

v3 Knowledgebase

[Plugin for devs] Custom Meta Tags

Hello,The plugin I am providing here allows you to easily edit the meta tags in any page. It is intended for developers or advanced users. It will not give you a section in the AdminCP or anywhere you can click and change the text, it will instead just allow you to define a new entry in the setHeader call within a controller.I mean this plugin for new controllers, however many existing controllers have hooks where needed. In 2.0.6 I will do my best to provide even more hooks to make sure you get the maximum level of customization.Safety first:
- This plugin is provided "as is", without any guarantee that it will work for you. (I does work for me).Hook: template_getheader_setting
PHP:
foreach ($this->_aHeaders as $iKey => $aValue)
{
    if (isset(
$aValue['overwrite']) && is_array($aValue['overwrite']) && isset($this->_aHeaders[]))
    {
    foreach (
$aValue['overwrite'] as $sToken => $sNew)                
        foreach (
$this->_aHeaders[] as $iOriginalKey => $sValue)                                        
        
$this->_aHeaders[][$iOriginalKey] = preg_replace('/(<meta.*?name="'.$sToken.'".*?)content="[^"]+"([^>]*>)/''$1content="'.$sNew.'"$2'$this->_aHeaders[][$iOriginalKey]);                
    unset(
$this->_aHeaders[$iKey]['overwrite']);                
    }
    if (isset(
$aValue['remove']) && is_array($aValue['remove']) && isset($this->_aHeaders[]))        
    {
    foreach (
$aValue['remove'] as $sToken)
        foreach (
$this->_aHeaders[] as $iOriginalKey => $sValue)                    
        if (
strpos($this->_aHeaders[][$iOriginalKey], $sToken) !== false)
            unset(
$this->_aHeaders[][$iOriginalKey]);            
    unset(
$this->_aHeaders[$iKey]['remove']);
    }
Sample usage:
PHP:
class Module_Component_Controller_Index extends Phpfox_Component
{
...
$this->template()->setHeader('overwrite', array(
                
'description' =>
                    
Phpfox::getPhrase('module.phrase_variable', array(
                    
'var1' => 'value 1',
                    
'var2' => 'value 2'
                    
)
                    ),
                
'keywords' => getPhrase('module.phrase_variable_keywords')
                );
I trust you can see now that with this you can generate custom keywords and descriptions and etc...Hope someone finds it usefulEdit: Forgot to mention, you can also remove meta tags completely by using the 'remove' index instead of the 'overwrite'