Skip to content

Instantly share code, notes, and snippets.

@kricore
Created May 15, 2015 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kricore/2c9a5434748c5f5f6cf9 to your computer and use it in GitHub Desktop.
Save kricore/2c9a5434748c5f5f6cf9 to your computer and use it in GitHub Desktop.
K2 custom meta based on extrafields
<?php
// Option 1 - content is already cleaned up.
// if AAA is set use it, else use BBB
$metacontent = ( isset($this->item->extraFields->AAA->value) && $this->item->extraFields->AAA->value != '' ) ? $this->item->extraFields->AAA->value : $this->item->extraFields->BBB->value;
$doc->addCustomTag('<meta name="anything" content="'.$metacontent.'" />');
?>
<?php // option two the content needs cleaning
// Clean the content prior to the assignment
$safe = array("&#39;", "&#34;");
$nonsafe = array("'", "\"");
// Cleanit up
$fieldone = (isset($this->item->extraFields->AAA->value) ? str_replace( $nonsafe, $safe, $this->item->extraFields->AAA->value ) : '' );
$fieldtwo = (isset($this->item->extraFields->BBB->value) ? str_replace( $nonsafe, $safe, $this->item->extraFields->BBB->value ) : '' );
// Assign the meta's content
$metacontent = ( isset($fieldone) && $fieldone != '' ? $fieldone : $fieldtwo );
$doc->addCustomTag('<meta name="anything" content="'.$metacontent.'" />');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment