Conversation
supportIt would be great if we could trim the excerpt to a specific number of words. Would you consider adding this feature? Either as a setting or as a hook to allow other themes to set the number of words. Thanks! https://wordpress.org/plugins/cp-related-posts/
Hi, The feature is available in the current version of the plugin, but unfortunately would be needed modify the plugin’s code. I promise to publish an update for controlling this parameter visually from the plugin’s settings. Please, follow the steps below: 1. Open the “/wp-content/plugins/cp-related-posts/cp-related-posts.php” file with the text editor your choice. 2. Go to the snippet of code: wp_trim_words( strip_shortcodes( $related_posts[ $i ]->post_content ) ) and pass the number of words as the second parameter. By default the wp_trim_words method returns the first 55 words of the text that is passed as first parameter. For example, if you want to display in the excerpt only the first 30 words, modifies the previous code like follow: wp_trim_words( strip_shortcodes( $related_posts[ $i ]->post_content ), 30 ) and that’s all. Best regards.
Thank you. I was hesitant to hack the module code since the changes would be wiped out in the next upgrade but if you intend to provide the functionality in the next version then that’s awesome.
Hi, I’m sorry for delay. Yes, in the next upgrade of the plugin, I’ll include the possibility to select the number of words to display in the articles’ summaries, from the plugin’s settings. Best regards.
Perfect, thanks so much!
Hi, The feature is available in the current version of the plugin, but unfortunately would be needed modify the plugin’s code. I promise to publish an update for controlling this parameter visually from the plugin’s settings. Please, follow the steps below: 1. Open the “/wp-content/plugins/cp-related-posts/cp-related-posts.php” file with the text editor your choice. 2. Go to the snippet of code: wp_trim_words( strip_shortcodes( $related_posts[ $i ]->post_content ) ) and pass the number of words as the second parameter. By default the wp_trim_words method returns the first 55 words of the text that is passed as first parameter. For example, if you want to display in the excerpt only the first 30 words, modifies the previous code like follow: wp_trim_words( strip_shortcodes( $related_posts[ $i ]->post_content ), 30 ) and that’s all. Best regards.
Thank you. I was hesitant to hack the module code since the changes would be wiped out in the next upgrade but if you intend to provide the functionality in the next version then that’s awesome.
Hi, I’m sorry for delay. Yes, in the next upgrade of the plugin, I’ll include the possibility to select the number of words to display in the articles’ summaries, from the plugin’s settings. Best regards.
Perfect, thanks so much!