Aleš Sýkora wrote

Custom excerpt lenght in Oxygen and WordPress

28. 5. 2021 in ,

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 funcionality plugin and use it in Oxygen Builder.

Thanks to https://stackoverflow.com/a/17177847.

Custom code:

/**
* Custom excerpt length.
*
* @link https://stackoverflow.com/a/17177847
*
* @param int $limit The number of words.
*/
function excerpt( $limit ) {
return wp_trim_words( get_the_excerpt(), $limit );
}

Then go to Oxygen builder and add custom PHP return value, when adding dynamic data field.

Inserting dynamic data from custom PHP function in Oxygen

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.

Oxygen PHP function call

The shortcode for custom excerpt lenght in Oxygen then looks like this:

[oxygen data='phpfunction' function='excerpt' arguments='8']

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Translate Phone number error message in Fluent Forms
15. 4. 2021 in
If you want to translate the error message, when user fill in wrong phone number in fluent forms, you can use this custom snippet:
Read More
Aleš Sýkora wrote
Oxygen builder – default media queries
24. 3. 2021 in ,
Default media queries of Oxygen. You can change them in Global Settings > Global Styles > Width & Breakpoints.
Read More
Aleš Sýkora wrote
Display list of WooCommerce categories
19. 2. 2021 in
If you need to display list of all WooCommerce categories without products, you can use my code. It will display all categories with link to their archive page. It will also display category image, name of course and count of products inside the category. It is all wrapped in HTML with OxyNinja framework applied. So […]
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram