Last active
March 27, 2017 23:04
-
-
Save carasmo/062096f8d37bd6ad9a8b9dbbe0c32cc1 to your computer and use it in GitHub Desktop.
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 | |
//don't re-add | |
/** | |
* | |
* custom entry content : replace the archive content with your own build for the excerpt/content limit | |
* | |
*/ | |
function yourprefix_do_custom_entry_content() { | |
if ( ! is_singular() ) : | |
remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); | |
add_action( 'genesis_entry_content', 'yourprefix_build_archive_entry_content' ); | |
endif; | |
} | |
add_action( 'genesis_before', 'yourprefix_do_custom_entry_content' ); | |
/** | |
* | |
* custom entry content for archives | |
* | |
*/ | |
function yourprefix_build_archive_entry_content() { | |
//get the limit setting in Genesis Theme Settings | |
$limit = genesis_get_option( 'content_archive_limit', GENESIS_SETTINGS_FIELD ); | |
//build the content with tags, balance the tags, and apply the limit to it | |
$content = get_the_content(); //the raw content unformatted | |
$content = preg_replace("/<img[^>]+\>/i", " ", $content ); // remove images | |
$content = preg_replace("/<embed[^>]+>/i", " ", $content, 1); // remove embeds | |
$content = apply_filters( 'the_content', $content ); //run the raw content though the filter to put the tags in | |
$content = str_replace(']]>', ']]>', $content); //remove shortcodes (a must) | |
$content = substr( $content, 0, $limit ); //apply the limit setting | |
$content = substr( $content, 0, strrpos( $content, ' ') ) . " …"; //add the ellipses | |
$content = force_balance_tags( $content ); //close any open tags | |
//remove links (optional) the link tag will close if the content clips at that tag. | |
$content = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $content ); | |
//build readmore | |
$readmore = '<p><a href="' . get_permalink() . '">Continue Reading</a></p>'; | |
echo $content . $readmore; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment