Aleš Sýkora / November 28, 2023 / 3 comments
Custom excerpt length in Oxygen, Bricks and WordPress
2 min read / Oxygen Builder, Plugins, WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: Need to display smaller amount of words in some WordPress excerpts? Use custom function! Put the code below to your code snippets plugin or your custom functionality plugin and use it in Oxygen Builder. Thanks to https://stackoverflow.com/a/17177847. Notice: I changed the name of function from “excerpt” to “great_tit_excerpt” because of conflict with some plugins. Custom…
Need to display smaller amount of words in some WordPress excerpts? Use custom function! Put the code below to your code snippets plugin or your custom functionality plugin and use it in Oxygen Builder.
Thanks to https://stackoverflow.com/a/17177847.
Notice: I changed the name of function from “excerpt” to “great_tit_excerpt” because of conflict with some plugins.
Custom code:
/**
* Custom excerpt length.
*
* @link https://stackoverflow.com/a/17177847
*
* @param int $limit The number of words.
*/
function great_tit_excerpt( $limit ) {
return wp_trim_words( get_the_excerpt(), $limit );
}
Oxygen Buider Dynamic Data
Then go to Oxygen builder and add custom PHP return value, when adding dynamic data field.
In PHP function write name of function to the first row input and number of words to the second input. For example this input returns excerpt of maximum size 8 words in Oxygen.
The shortcode for custom excerpt length in Oxygen then looks like this:
[oxygen data='phpfunction' function='great_tit_excerpt' arguments='8']
Bricks Builder Dynamic Data
In Bricks builder, you don’t need the custom function. You just add the number of words you want from the excerpt. For example: Need to display smaller amount of words in some WordPress…
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻
Stas
Thanks! Its Work!
cengiz
You made my day. Many thanks!
Aleš Sýkora
Happy to hear that! You’re welcome.