-
-
Save stalukder03/b6bf06abc17eaec2cf21d8c43d45ac0a to your computer and use it in GitHub Desktop.
Wordpress Custom Excerpt function
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 | |
function get_excerpt($count, $post_id){ | |
$permalink = get_permalink($post_id); | |
$excerpt = get_post($post_id); | |
$excerpt = $excerpt->post_content; | |
$excerpt = strip_tags($excerpt); | |
$excerpt = substr($excerpt, 0, $count); | |
$excerpt = substr($excerpt, 0, strripos($excerpt, " ")); | |
$excerpt = $excerpt; | |
// Want a read more link and ellipsis, remove the line above this and replace it with the one below. | |
$excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>'; | |
return $excerpt; | |
} | |
?> |
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 | |
// When using loop first arg is no. of chars you want displayed second arg is passing the global post ID. | |
echo get_excerpt(100, $post_id); | |
// When using in custom get_posts loop | |
echo get_excerpt(100, $custom_foreach->ID); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment