/** * Convert a Twitter card into <meta name="" content=""> pairs * * @since 1.0.0 * * @return string HTML <meta> elements */ public static function buildMetaElements() { $card = \Twitter\WordPress\Cards\Generator::get(); if (!$card) { return ''; } /** * Filter associative array of Twitter Card values * * Resulting array will be output to the page as <meta> elements * All keys receive the "twitter:" prefix inside a name attribute before output * Structured values are passed as an array. example: 'image' => array( 'src' => 'http://example.com/i.jpg', 'width' => 640 ) * * @since 1.0.0 * * @param array $card_properties associative array of Twitter Card values { * @type string card property name * @type string|int|array property value * } */ $card_properties = apply_filters('twitter_card', $card->toArray()); if (!is_array($card_properties) || empty($card_properties)) { return ''; } $html = ''; foreach ($card_properties as $name => $content) { if (is_array($content) && $name) { foreach ($content as $structured_name => $structured_value) { $html .= \Twitter\WordPress\Head\MetaElement::fromNameContentPair($structured_name === 'src' ? $name : $name . ':' . $structured_name, $structured_value); } } else { $html .= \Twitter\WordPress\Head\MetaElement::fromNameContentPair($name, $content); } } return $html; }
/** * Build HTML meta elements to be included as children of <head> * * @since 1.0.0 * * @return string HTML meta elements */ public static function buildMetaElements() { $meta = array(); $widget_options = static::getWidgetOptions(); if (!empty($widget_options)) { $meta = static::widgetOptionsToMetaElementPairs($widget_options); } unset($widget_options); // opt out of tailored audiences if (static::optOutOfTwitterTailoredAudiences()) { $meta['dnt'] = 'on'; } // powered by Twitter plugin for WordPress // please leave for stats $meta['partner'] = 'tfwp'; if (empty($meta)) { return ''; } $html = ''; foreach ($meta as $name => $content) { $html .= \Twitter\WordPress\Head\MetaElement::fromNameContentPair($name, $content); } return $html; }