Limited Time Sale - 10% Discount! Use Code:U5ZBQTEY

Custom Excerpt


This document explains how to customize the excerpt displayed in the Portfolio Posts Pro plugin when the Show Excerpt option is turned on.

Once the Show Excerpt option is turned on in the Design tab of the module’s settings, an Excerpt Limit option will appear allowing you to set the length (in characters) of the excerpt. If the post or custom post type contains an actual excerpt, this will be truncated and displayed. If no excerpt is set, Portfolio Posts Pro will truncate the content of the post and display that.

In either case, we are stripping the HTML from the excerpt to prevent broken HTML on the page. For example, if an opening paragraph tag is outputted in your excerpt but the closing tag is not outputted because the excerpt is truncated before the closing tag, this would break the page that is displaying the excerpt.

However, we can also understand that in some cases you may not want to strip the HTML from the output. For this we have created a filter. The code below is a modified version of the function we use to output the excerpt. We’ve commented the code to help you understand what we are doing.

In a nutshell, if the post has an excerpt, we are displaying it without removing any HTML. If the post does not have an excerpt, we are truncating the post content and removing any Divi shortcodes generated by the Divi Builder and removing any HTML. The variable $charlength is set to 270. Adjust this value to increase or decrease the size of the excerpt.

Pin It on Pinterest

Share This