Last active
August 29, 2015 14:26
-
-
Save robertdevore/388b64725c2a5d7fcd96 to your computer and use it in GitHub Desktop.
WordPress: the_excerpt customizations
This file contains hidden or 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 | |
/** | |
* Changing the excerpt length | |
* | |
* the default length is 55 words and the code below changes it to 25 words | |
*/ | |
function custom_excerpt_length( $length ) { | |
return 25; | |
} | |
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); | |
/** | |
* Adding a 'Read More' link | |
* | |
* the code below removes the hideous '[...]' from the end of the_excerpt() and adds '... Read More' | |
*/ | |
function custom_excerpt_more( $more ) { | |
return ' ... <a class="read-more" href="' . get_permalink( get_the_ID() ) . '">' . __( 'Read More', 'your-text-domain' ) . '</a>'; | |
} | |
add_filter( 'excerpt_more', 'custom_excerpt_more' ); | |
/** | |
* Adding css class to <p> wrapper | |
* | |
* The code below adds the class 'excerpt' to the <p> tag that wraps around the excerpt | |
*/ | |
function add_class_to_excerpt( $excerpt ) { | |
return str_replace('<p', '<p class="excerpt"', $excerpt); | |
} | |
add_filter( "the_excerpt", "add_class_to_excerpt" ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment