{"id":331,"date":"2013-02-22T15:25:21","date_gmt":"2013-02-22T21:25:21","guid":{"rendered":"http:\/\/www.marcblase.com\/blog\/?p=331"},"modified":"2013-02-22T15:36:05","modified_gmt":"2013-02-22T21:36:05","slug":"custom-excerpt-lengths-in-wordpress","status":"publish","type":"post","link":"https:\/\/ma.rcbla.se\/blog\/2013\/02\/custom-excerpt-lengths-in-wordpress\/","title":{"rendered":"Custom Excerpt Lengths in WordPress"},"content":{"rendered":"<p>Sometimes shortened content just needs to be even shorter. <\/p>\n<p>So, when you need that post\/page content for a content slider or the like, give this little bit of code a go:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction my_excerpt($limit) {\r\n\t$excerpt = explode(' ', get_the_excerpt(), $limit);\r\n\tif (count($excerpt)&gt;=$limit) {\r\n\t\tarray_pop($excerpt);\r\n\t\t$excerpt = implode(&quot; &quot;,$excerpt).'...';\r\n\t} else {\r\n\t\t$excerpt = implode(&quot; &quot;,$excerpt);\r\n\t} \r\n\t$excerpt = preg_replace('`\\&#x5B;&#x5B;^\\]]*\\]`','',$excerpt);\r\n\treturn $excerpt;\r\n}\r\n\r\nfunction my_content($limit) {\r\n\t$content = explode(' ', get_the_content(), $limit);\r\n\tif (count($content)&gt;=$limit) {\r\n\t\tarray_pop($content);\r\n\t\t$content = implode(&quot; &quot;,$content).'...';\r\n\t} else {\r\n\t\t$content = implode(&quot; &quot;,$content);\r\n\t} \r\n\t$content = preg_replace('\/\\&#x5B;.+\\]\/','', $content);\r\n\t$content = apply_filters('the_content', $content); \r\n\t$content = str_replace(']]&gt;', ']]&amp;gt;', $content);\r\n\treturn $content;\r\n}\r\n<\/pre>\n<p>Code thanks to a poster at <a href=\"http:\/\/stackoverflow.com\/questions\/4082662\/multiple-excerpt-lengths-in-wordpress\">Stack Overflow<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes shortened content just needs to be even shorter. So, when you need that post\/page content for a content slider or the like, give this little bit of code a go: function my_excerpt($limit) { $excerpt = explode(&#8216; &#8216;, get_the_excerpt(), $limit); if (count($excerpt)&gt;=$limit) { array_pop($excerpt); $excerpt = implode(&quot; &quot;,$excerpt).&#8217;&#8230;&#8217;; } else { $excerpt = implode(&quot; &quot;,$excerpt); [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-331","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/comments?post=331"}],"version-history":[{"count":3,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/331\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/331\/revisions\/333"}],"wp:attachment":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/media?parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/categories?post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/tags?post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}