Created
May 15, 2015 12:42
-
-
Save kricore/2c9a5434748c5f5f6cf9 to your computer and use it in GitHub Desktop.
K2 custom meta based on extrafields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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("'", """); | |
$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