\n"; if ($desc !== '') { printf('' . "\n", esc_attr($desc)); } printf('' . "\n", is_singular() ? 'article' : 'website'); printf('' . "\n", esc_attr($title)); if ($desc !== '') { printf('' . "\n", esc_attr($desc)); } printf('' . "\n", esc_url($url)); printf('' . "\n", esc_attr(get_bloginfo('name'))); if ($image !== '') { printf('' . "\n", esc_url($image)); // With an image, use the large card — otherwise Twitter renders a very small summary echo '' . "\n"; } else { echo '' . "\n"; } } /** * Where the summary comes from, most specific first: * the post excerpt -> truncated body copy -> the term description -> the site tagline. * * Truncation counts characters, not bytes — cutting by bytes on a multi-byte site splits a * character in half. */ private static function description(): string { if (is_singular()) { $post = get_post(); if ($post) { $ex = trim((string) $post->post_excerpt); if ($ex !== '') { return self::clip($ex); } $body = trim(wp_strip_all_tags(strip_shortcodes((string) $post->post_content))); if ($body !== '') { return self::clip($body); } } } if (is_tax() || is_category() || is_tag()) { $t = get_queried_object(); if ($t && !empty($t->description)) { return self::clip(wp_strip_all_tags($t->description)); } } return self::clip((string) get_bloginfo('description')); } private static function clip(string $s, int $len = 155): string { $s = trim(preg_replace('/\s+/u', ' ', $s)); return Str::len($s) > $len ? Str::sub($s, 0, $len - 1) . '…' : $s; } private static function image(): string { if (is_singular()) { $id = get_post_thumbnail_id(); if ($id) { $url = wp_get_attachment_image_url($id, 'large'); if ($url) { return $url; } } } // With no featured image, fall back to the theme's default cover — a share with an image // and one without have very different click-through rates $fallback = apply_filters('aumframe/fallback_image', '', 0); return is_string($fallback) ? $fallback : ''; } }