{"id":4933,"date":"2025-01-07T10:24:36","date_gmt":"2025-01-07T15:24:36","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=4933"},"modified":"2025-01-07T10:24:37","modified_gmt":"2025-01-07T15:24:37","slug":"trimmiddle","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/trimmiddle\/","title":{"rendered":"trimMiddle()"},"content":{"rendered":"\n<p>CSS can truncate text <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/text-overflow\">on a single line<\/a> or <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/-webkit-line-clamp\">on multiple lines<\/a>, but it always does so <em>from the end of the text.<\/em> I&#8217;ve seen a (bad) trick reversing the text direction to trim text from the front instead, but never from the middle. <\/p>\n\n\n\n<p><a href=\"https:\/\/christianheilmann.com\/2025\/01\/03\/trimmiddle-the-missing-string-trim-command\/\">Christian Heilmann wrote a package<\/a> to help with this. I agree it&#8217;s a better solution <em>particularly<\/em> for file names\/paths as both the beginning and ending hold more important information than the middle.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS can truncate text on a single line or on multiple lines, but it always does so from the end of the text. I&#8217;ve seen a (bad) trick reversing the text direction to trim text from the front instead, but never from the middle. Christian Heilmann wrote a package to help with this. I agree [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4935,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[3,277,278],"class_list":["post-4933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-javascript","tag-strings","tag-truncation"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2025\/01\/pexels-photo-7697673.jpeg?fit=1880%2C1253&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/4933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=4933"}],"version-history":[{"count":3,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/4933\/revisions"}],"predecessor-version":[{"id":4939,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/4933\/revisions\/4939"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/4935"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=4933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=4933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=4933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}