Created
April 24, 2012 23:13
-
-
Save dylanized/2484502 to your computer and use it in GitHub Desktop.
Flexible WP Excerpt Snippet
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 // outside the loop | |
// empty more text on custom excerpt | |
function custom_excerpt_more( $more ) { | |
return ''; | |
} | |
add_filter( 'excerpt_more', 'custom_excerpt_more' ); | |
// instantiate global excerpt string | |
$more_text = "Read More…"; | |
?> | |
<?php // inside the loop | |
if (!is_singular()) { | |
global $more_text; | |
if (has_excerpt()) { | |
// if it has a custom excerpt | |
the_excerpt(); | |
?> | |
<p><a class="more-link" href="<?php the_permalink() ?>"><?= $more_text ?></a></p> | |
<?php | |
} elseif (strpos($post->post_content, '<!--more-->')) { | |
// if it it has a break tag | |
the_content($more_text); | |
} else { | |
// display the default excerpt | |
the_excerpt(); | |
?> | |
<p><a class="more-link" href="<?php the_permalink() ?>"><?= $more_text ?></a></p> | |
<?php | |
} | |
} else { | |
the_content(); | |
edit_post_link('Edit Post', '<div><small>', '</small></div>'); | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment