Created
August 12, 2021 12:55
-
-
Save eclarrrk/daa45c4d0c476903811e05c46da0a92f to your computer and use it in GitHub Desktop.
How to show an excerpt for pages in WordPress search results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( 'page' === get_post_type() ) { | |
echo wp_trim_words( get_the_content(), 30, '...' ); | |
} else { | |
the_excerpt(); | |
} | |
// wp_trim_words() docs: https://developer.wordpress.org/reference/functions/wp_trim_words/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment