PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.12.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.12.0
2.12.0 2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk All 53 releases
← All changes | includes/seo/class-social-meta-manager.php +82 -32 2.4.0 → 2.12.0 View file →
@@ -148,14 +148,23 @@
148 148 // og:title must render the full resolved Open Graph title. The 60-char
149 149 // cap in optimize_title_for_platform() is an SEO-title recommendation for
150 150 // search results and does not apply to the og:title social tag, so use the
151 151 // resolved title verbatim (falling back to the site name when empty).
152 - $og_tags['og:title'] = ($data['title'] ?? '') !== '' ? $data['title'] : get_bloginfo('name');
152 + // Stripped: a title carrying markup is attribute-escaped into this tag,
153 + // so the reader sees a literal `<em>` rather than emphasis (#640).
154 + $og_tags['og:title'] = \ThinkRank\Frontend\SEO_Manager::strip_title_tags(
155 + ($data['title'] ?? '') !== '' ? (string) $data['title'] : (string) get_bloginfo('name')
156 + );
153 157 // `?:` rather than `??`: the key is always present, seeded as '', so the
154 158 // null-coalesce could never reach the fallback. og:url was emitted empty
155 159 // and then dropped by the !empty() guard in output_social_og_tags(),
156 160 // which is why archives carried no og:url at all (#388).
157 - $og_tags['og:url'] = ($data['url'] ?? '') !== '' ? $data['url'] : $this->get_current_url();
161 + // Normalized for the site's scheme preference, so og:url and the
162 + // canonical can never disagree about http vs https (#638); the same
163 + // consistency #182 was about.
164 + $og_tags['og:url'] = \ThinkRank\SEO\Url_Scheme::apply(
165 + ($data['url'] ?? '') !== '' ? $data['url'] : $this->get_current_url()
166 + );
158 167
159 168 // Image handling with optimization
160 169 if (!empty($data['image'])) {
161 170 $optimized_image = $this->optimize_image_for_platform($data['image'], $platform);
@@ -222,9 +231,11 @@
222 231 // to the resolved og:title/SEO title. Render it in full — the length cap
223 232 // in optimize_title_for_platform() is an SEO-title recommendation for
224 233 // search results, not a rule for the twitter:title social tag.
225 234 $twitter_title = ($data['twitter_title'] ?? '') !== '' ? $data['twitter_title'] : ($data['title'] ?? '');
226 - $twitter_tags['twitter:title'] = $twitter_title !== '' ? $twitter_title : get_bloginfo('name');
235 + $twitter_tags['twitter:title'] = \ThinkRank\Frontend\SEO_Manager::strip_title_tags(
236 + $twitter_title !== '' ? (string) $twitter_title : (string) get_bloginfo('name')
237 + );
227 238
228 239 // Recommended tags. Prefer a per-object Twitter-specific description,
229 240 // falling back to the resolved OG/meta description — mirroring the
230 241 // twitter:title cascade above. This lookup did not exist, so a Twitter
@@ -957,8 +968,12 @@
957 968
958 969 $settings = $this->get_settings($context_type, $context_id);
959 970 $output = [
960 971 'og_tags' => [],
972 + // Secondary og:image entries. A separate list because $og_tags is
973 + // keyed by property name and so can hold exactly one 'og:image'
974 + // (#636); the emitter writes these straight after the primary.
975 + 'og_extra_images' => [],
961 976 'twitter_tags' => [],
962 977 'meta_tags' => [],
963 978 'platform_tags' => [],
964 979 // Per-feature flags so each emitter can honor its own toggle. The
@@ -992,8 +1007,18 @@
992 1007 // Add custom OG tags
993 1008 if (!empty($settings['custom_og_tags'])) {
994 1009 $output['og_tags'] = array_merge($output['og_tags'], $settings['custom_og_tags']);
995 1010 }
1011 +
1012 + // Alternatives to offer after the primary image. Collected from the
1013 + // resolved primary rather than re-deriving it, so the two can never
1014 + // disagree about which image is the main one.
1015 + if (!empty($settings['og_multiple_images'])) {
1016 + $output['og_extra_images'] = Social_Images::additional(
1017 + (int) $context_id,
1018 + (string) ($output['og_tags']['og:image'] ?? '')
1019 + );
1020 + }
996 1021 }
997 1022
998 1023 // Generate Twitter Card tags if enabled
999 1024 if ($twitter_enabled) {
@@ -1046,8 +1071,13 @@
1046 1071 */
1047 1072 private const SITE_ONLY_KEYS = [
1048 1073 'enable_open_graph',
1049 1074 'enable_twitter_cards',
1075 + // Same shape as the two above and the same trap: a site-wide switch
1076 + // with no per-context equivalent. Left out, it read as on while the
1077 + // homepage rendered and as off on every post and page — which is where
1078 + // the alternatives it controls actually come from (#636).
1079 + 'og_multiple_images',
1050 1080 ];
1051 1081
1052 1082 /**
1053 1083 * Get settings for a context, inheriting the site-wide default images
@@ -1130,8 +1160,12 @@
1130 1160 'og_locale' => '',
1131 1161 'default_og_image' => '',
1132 1162 'og_image_width' => 1200,
1133 1163 'og_image_height' => 630,
1164 + // Offer alternative og:image tags after the primary one (#636).
1165 + // Off by default: a page that shares with one image today must
1166 + // keep sharing with that image after an update.
1167 + 'og_multiple_images' => false,
1134 1168
1135 1169 // Twitter Cards settings
1136 1170 'enable_twitter_cards' => true,
1137 1171 'twitter_username' => '',
@@ -1171,8 +1205,15 @@
1171 1205 'fallback_to_excerpt' => true,
1172 1206 'strip_html_tags' => true,
1173 1207 'max_description_length' => 160,
1174 1208
1209 + // oEmbed card (#637). All three default off: this rewrites what
1210 + // other people's sites display, so an upgrade must not silently
1211 + // change a card an existing embed has been showing for months.
1212 + 'oembed_use_seo_title' => false,
1213 + 'oembed_use_social_image' => false,
1214 + 'oembed_remove_author' => false,
1215 +
1175 1216 // Legacy format for backward compatibility (only when needed)
1176 1217 'custom_og_tags' => [],
1177 1218 'image_optimization' => true,
1178 1219 'auto_generate' => true
@@ -1801,8 +1842,12 @@
1801 1842 $image_id = get_post_thumbnail_id($post);
1802 1843 if ($image_id) {
1803 1844 $image_data = wp_get_attachment_image_src($image_id, 'large');
1804 1845 if (!empty($image_data[0])) {
1846 + // The ID is in hand here and gone once this returns a
1847 + // bare URL; say so rather than have the tag builders look
1848 + // it up again, twice, with a URL core cannot match (#847).
1849 + Attachment_Lookup::remember((string) $image_data[0], (int) $image_id);
1805 1850 return $image_data[0];
1806 1851 }
1807 1852 }
1808 1853 }
@@ -1849,8 +1894,12 @@
1849 1894 $image_id = get_post_thumbnail_id($post);
1850 1895 if ($image_id) {
1851 1896 $image_data = wp_get_attachment_image_src($image_id, 'large');
1852 1897 if (!empty($image_data[0])) {
1898 + // The ID is in hand here and gone once this returns a
1899 + // bare URL; say so rather than have the tag builders look
1900 + // it up again, twice, with a URL core cannot match (#847).
1901 + Attachment_Lookup::remember((string) $image_data[0], (int) $image_id);
1853 1902 return $image_data[0];
1854 1903 }
1855 1904 }
1856 1905 }
@@ -2082,16 +2131,13 @@
2082 2131 if (mb_strlen($title) <= $max_length) {
2083 2132 return $title;
2084 2133 }
2085 2134
2086 - // Truncate at word boundary
2087 - $truncated = wp_trim_words($title, 10, '');
2088 - if (mb_strlen($truncated) <= $max_length) {
2089 - return $truncated;
2090 - }
2091 -
2092 - // Hard truncate if necessary
2093 - return mb_substr($title, 0, $max_length - 3) . '...';
2135 + // Truncate at a word boundary where there is one, and hard-cut where
2136 + // there is not. This used to try wp_trim_words() first, which counts
2137 + // CHARACTERS on th/ja/zh_* — so it returned ~10 characters, passed the
2138 + // $max_length check below, and that was accepted as the title (#687).
2139 + return \ThinkRank\Core\Seo_Text::trim_to_length($title, $max_length);
2094 2140 }
2095 2141
2096 2142 /**
2097 2143 * Optimize description for platform requirements
@@ -2114,16 +2160,14 @@
2114 2160 if (mb_strlen($description) <= $max_length) {
2115 2161 return $description;
2116 2162 }
2117 2163
2118 - // Truncate at word boundary
2119 - $truncated = wp_trim_words($description, 25, '');
2120 - if (mb_strlen($truncated) <= $max_length) {
2121 - return $truncated;
2122 - }
2123 -
2124 - // Hard truncate if necessary
2125 - return mb_substr($description, 0, $max_length - 3) . '...';
2164 + // Truncate at a word boundary where there is one, and hard-cut where
2165 + // there is not. This used to try wp_trim_words() first, which counts
2166 + // words in English but CHARACTERS in th/ja/zh_* — so on those locales
2167 + // it returned ~25 characters, comfortably under $max_length, and that
2168 + // was accepted as the answer (#687).
2169 + return \ThinkRank\Core\Seo_Text::trim_to_length($description, $max_length);
2126 2170 }
2127 2171
2128 2172 /**
2129 2173 * Optimize image for platform requirements
@@ -2148,21 +2192,23 @@
2148 2192 if (empty($image_url)) {
2149 2193 return $image_data;
2150 2194 }
2151 2195
2152 - // Get image metadata
2153 - $attachment_id = attachment_url_to_postid($image_url);
2196 + // Get image metadata. The dimensions are those of the file this URL
2197 + // names — usually a generated size — not of the original upload, so
2198 + // the width and height published beside it describe the same image.
2199 + $attachment_id = Attachment_Lookup::id_from_url($image_url);
2154 2200 if ($attachment_id) {
2155 2201 $image_meta = wp_get_attachment_metadata($attachment_id);
2156 2202 $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
2157 - $mime_type = get_post_mime_type($attachment_id);
2203 + $image_file = Attachment_Lookup::describe($attachment_id, $image_url);
2158 2204
2159 2205 if ($image_meta && isset($image_meta['width'], $image_meta['height'])) {
2160 - $width = (int) $image_meta['width'];
2161 - $height = (int) $image_meta['height'];
2206 + $width = $image_file['width'];
2207 + $height = $image_file['height'];
2162 2208
2163 2209 $image_data['alt'] = $image_alt ?: '';
2164 - $image_data['type'] = $mime_type ?: '';
2210 + $image_data['type'] = $image_file['type'];
2165 2211
2166 2212 // SVGs and other vector uploads store 0x0 metadata. Dimension
2167 2213 // checks are meaningless there and dividing by 0 is fatal.
2168 2214 if ($width > 0 && $height > 0) {
@@ -2214,8 +2260,9 @@
2214 2260 $custom_logo_id = get_theme_mod('custom_logo');
2215 2261 if ($custom_logo_id) {
2216 2262 $logo_data = wp_get_attachment_image_src($custom_logo_id, 'large');
2217 2263 if ($logo_data) {
2264 + Attachment_Lookup::remember((string) $logo_data[0], (int) $custom_logo_id);
2218 2265 return $logo_data[0];
2219 2266 }
2220 2267 }
2221 2268
@@ -2223,8 +2270,9 @@
2223 2270 $site_icon_id = get_option('site_icon');
2224 2271 if ($site_icon_id) {
2225 2272 $icon_data = wp_get_attachment_image_src($site_icon_id, 'large');
2226 2273 if ($icon_data) {
2274 + Attachment_Lookup::remember((string) $icon_data[0], (int) $site_icon_id);
2227 2275 return $icon_data[0];
2228 2276 }
2229 2277 }
2230 2278
@@ -2651,12 +2699,13 @@
2651 2699 private function make_description_catchy(string $description): string {
2652 2700 // TikTok prefers short, catchy descriptions
2653 2701 $catchy_words = ['viral', 'trending', 'must-see', 'epic', 'mind-blowing'];
2654 2702
2655 - // Limit to 100 characters for TikTok
2656 - if (strlen($description) > 100) {
2657 - $description = substr($description, 0, 97) . '...';
2658 - }
2703 + // Limit to 100 characters for TikTok. strlen()/substr() count BYTES,
2704 + // so this both fired three times too early on Thai/CJK text and cut
2705 + // mid-character, emitting a broken UTF-8 sequence rather than a short
2706 + // description (#687).
2707 + $description = \ThinkRank\Core\Seo_Text::trim_to_length($description, 100);
2659 2708
2660 2709 if (!preg_match('/\b(' . implode('|', $catchy_words) . ')\b/i', $description)) {
2661 2710 $description = '🔥 ' . $description;
2662 2711 }
@@ -2980,13 +3029,14 @@
2980 3029 return $validation;
2981 3030 }
2982 3031
2983 3032 // Get image metadata if it's a local attachment
2984 - $attachment_id = attachment_url_to_postid($image_url);
3033 + $attachment_id = Attachment_Lookup::id_from_url($image_url);
2985 3034 if ($attachment_id) {
2986 3035 $image_meta = wp_get_attachment_metadata($attachment_id);
2987 - $meta_width = isset($image_meta['width']) ? (int) $image_meta['width'] : 0;
2988 - $meta_height = isset($image_meta['height']) ? (int) $image_meta['height'] : 0;
3036 + $image_file = Attachment_Lookup::describe($attachment_id, $image_url);
3037 + $meta_width = $image_file['width'];
3038 + $meta_height = $image_file['height'];
2989 3039
2990 3040 // SVGs and other vector uploads store 0x0 metadata — skip the
2991 3041 // dimension/ratio checks instead of dividing by 0.
2992 3042 if ($image_meta && $meta_width > 0 && $meta_height > 0) {